I have a Calc spreadsheet on which I have used Form Design mode to add several Push-Button controls to each of two sheets. The buttons initiate Basic macro code that resides in the Standard Module of the spreadsheet itself (i.e. NOT in the My Macros Module.) I want the macro code initiated by a button-click on Sheet-1 to be able to iterate over all the Controls on Sheet-2 to find a specific button Control so I can manipulate its properties.
Using the oEvent passed to the macro by a button-click on Sheet-1, I can manipulate the properties of the clicked button:
oSource = oEvent.Source
oModel = oSource.getModel()
oModel.(Property) = value
And I can manipulate any/all Controls on the same Sheet (in the same Container as the oEvent?) using:
For Each control In oSource.Context.Controls
control.Model.(Property) = (Value)
Next
But I want to manipulate the properties of the Controls that reside on Sheet-2. I have been unable to find a way to locate and access the Controls on a sheet different from the one on which the button-click oEvent occurred. Note that the Controls reside directly on the Sheets and NOT on a Dialog Form.
Edit #1
After further research, I discovered that
oSheet = ThisComponent.Sheets.getByName("SheetName")
oButton = oSheet.DrawPage.Forms.getByIndex(0).getByName("ButtonName")
oButton.(Property) = (Value)
will allow me to manipulate the properties of any Control on any Sheet provided I know the Name of the Sheet and the Name of the Control I want to manipulate. In my case, I know the required names, so I can use this technique as a “workaround.”
While this allows me to do what I wanted, it does not answer my original question, so I’m leaving the question un-answered for a bit longer to see if anyone can provide an answer.