We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question
0

Calc Basic select a chart

asked 2021-03-18 05:33:45 +0200

MikeMcClain46 gravatar image

updated 2021-03-19 23:48:40 +0200

It seems that folks are going down the wrong path so I'll simplify.

When I draw a chart in calc basic I would like to select it using a basic command.

ThisComponent.CurrentController.Select() works with cells and ranges but not charts.

What command will select a chart?

Thanks, Mike

PS: The last suggestion of using Ctrl+Z I can't test because at the moment trying to draw a chart crashes LO to the point that I must restart the GUI to even try calc again. MM

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2021-03-18 15:05:19 +0200

JohnSUN gravatar image

Select first shape on active sheet and with Tab key jump to next:

Sub SelectFirstShapeOnActiveSheet
Dim oCurrentController As Variant, oActiveSheet As Variant, oDrawPage As Variant
    oCurrentController = ThisComponent.getCurrentController()
    oActiveSheet = oCurrentController.getActiveSheet()
    oDrawPage = oActiveSheet.getDrawPage()
    If oDrawPage.hasElements() Then
        oCurrentController.Select(oDrawPage.getByIndex(0))
    EndIf
End Sub
edit flag offensive delete link more

Comments

Hi JohnSUN,

I copy/pasted your code and put a call to it right after drawing the chart but it isn't selected, still need to select with the mouse in order to delete the graph.

Where should I look to see why something that works for you doesn't for me?

Thanks, Mike

MikeMcClain46 gravatar imageMikeMcClain46 ( 2021-03-18 21:26:03 +0200 )edit

For some reason unbeknownst to me, neither of the offered suggestions worked for me.

Perhaps it's just as well since selecting the chart with the mouse then deleting it may well have been what was causing calc to crash.

Occasionally I would see this error message, "C++ code threw St9bad_alloc: std::bad_alloc".

Since I figured out how to delete the chart using oCharts.removeByName(), I've quit having crashes. Perhaps improperly disposing the chart was creating memory leaks unfortunately basic has no way to test that assumption that I know of.

None the less, I want to say thank you for the assistance offered.

Be Well, Mike

MikeMcClain46 gravatar imageMikeMcClain46 ( 2021-03-23 17:30:48 +0200 )edit
0

answered 2021-03-18 22:37:23 +0200

updated 2021-03-18 22:48:53 +0200

Hi, @MikeMcClain46

Sub DeleteFirstImageInserted
ThisComponent.getCurrentController().getActiveSheet().getDrawPage() _
.remove( ThisComponent.getCurrentController().getActiveSheet().getDrawPage().getByIndex(0))
'The (0) represents the first image inserted.
End Sub

If there is more than one image in the spreadsheet, adjust the macro for the correct image.

edit flag offensive delete link more

Comments

Thank you for that Sir.

There is also Charts.RemoveByName() and I wonder if there is a reason to prefer one over the other.

However that's for later, my current challenge as stated initially is how to select the chart in Basic so that after creating and viewing it all I need do is hit Delete to get it off the screen.

Thanks for your input.

Mike

MikeMcClain46 gravatar imageMikeMcClain46 ( 2021-03-19 03:23:24 +0200 )edit
1

after creating and viewing it all I need do is hit Delete to get it off the screen

Oh, remove LAST CREATED chart? What about deselect chart (click anywhere) and press Ctrl+Z?

JohnSUN gravatar imageJohnSUN ( 2021-03-19 06:41:00 +0200 )edit

Mr. Schiavinatto, I didn't realize until much later that Buttons are images and your solution deleted a couple of buttons off my page. Again thanks for your input. Mike

MikeMcClain46 gravatar imageMikeMcClain46 ( 2021-03-30 00:32:33 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2021-03-18 05:33:45 +0200

Seen: 43 times

Last updated: Mar 19