Project-A
Project-A

Reputation: 153

How to get the name of checkbox that I checked in libreoffice calc (macro)?

I have more than 40 check-boxes in a single calc sheet, and I don't want to code each one of them. I just want a clear working code to get the name of checkbox.

In this program I have to manually type the name for the check-box within the macro code:

A="CheckBox1"

This is all I have so far:

Sub Marco1
    Dim ocheckbox1
    Dim oForm
    Dim A
    A="CheckBox1"
    oForm = ThisComponent.Sheets(0).DrawPage.Forms.getByIndex(0)
    ocheckbox1 = oForm.getByName(A)
    if ocheckbox1.State = "0" then
        if MsgBox ("Are you sure ?Note: It can't be re-edited", 292) = 6 then
            ocheckbox1.Label = "Checked"
            ocheckbox1.Enabled="False"
        else
            ocheckbox1.Label = "Not Checked"
        End if
    End if
End Sub

Upvotes: 1

Views: 2744

Answers (1)

Lyrl
Lyrl

Reputation: 935

Assuming the macro is triggered by interaction with the checkbox:

Sub Macro1 (oEvent As Object)
    Dim oCheckbox1 As Object
    Dim sCheckbox1Name As String

    oCheckbox1 = oEvent.source.model
    sCheckbox1Name = oCheckbox1.Name
End Sub

Upvotes: 2

Related Questions