I have a Calc Sheet and create shapes on it by copying an existing shape, then modifying it by changing the name, the size, the position, the text on it etc. All works well, but… the shape also has a macro assigned to it to fire an action once the shape is clicked. The macro starts correctly. But I want to know which shape (preferable the name I gave it) started the macro.
I’ve read the Basic Guide 3.2 and the OOME 3.0 but they didn’t bring me any closer to the solution. The code I’ve found in this topic doesn’t help me either.
Sub Snippet2 Dim oCurrentSelection As Variant Dim oObj1 As Variant oCurrentSelection = ThisComponent.getCurrentSelection() oObj1 = oCurrentSelection.getByIndex(0) MsgBox oObj1.Name End Sub
Maybe because it’s for Draw (and thus on the DrawPage automatically?) but in Calc used as-is I get:
BASIC runtime error.
Property or method not found: getByIndex.
When I change the code slightly to
Sub Snippet2 Dim oCurrentSelection As Variant Dim oObj1 As Variant oCurrentSelection = ThisComponent.getCurrentSelection() oObj1 = oCurrentSelection.ImplementationName MsgBox oObj1 End Sub
I get to see either ScCellObj or ScCellRangeObj depending on what I had selected before I clicked the shape. Only when I right click the shape, then click another shape to fire the macro I see “com.sun.star.drawing.SvxShapeCollection”. But not from the shape I clicked because the shape I clicked isn’t really selected, it’s only clicked. Unlike a button which gets selected as soon as you click it.
So the question is, it there a way to find out which shape fired the macro? Does the DrawPage have a .getCurrentSelection? Is there another way to do this?
It would be great if I could send a parameter in my macro but there’s no place to define that. I can only select the macro, even if it has an argument
Sub Snippet2(oShape as object) MsgBox oShape.Name End Sub
I get an error:
Message: wrong number of parameters!
because the oShape isn’t set. Any push in the right direction is much appreciated and thanks in advance for your time.