how to rename of checkbox in order to refer to it in VBA code

cybersurfer5000

New Member
Joined
Apr 23, 2024
Messages
1
Office Version
  1. 365
Platform
  1. MacOS
Hi.
I use excel for Mac. I have 3 checkboxes. I want to refer to the checkboxes in my VBA code, however I cannot find the name of the checkbox. What I tried so far, is select a checkbox, go to the Formula tab -> Name manager and I see what is shown in the provided screenshot. None of the names seems to work when I put it in the VBA code. Anyone knows where to find the name of the checkbox, and also how to change it?
Thanks

Screen Shot 2024-04-23 at 11.34.49 PM.png

Sophia
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi,

I'm using the Windows version of Excel, but if you select your checkbox, the name should appear in the "Name Box" located to the left of the formula bar...

checkbox.jpg


Hope this helps!
 
Upvote 0
It is going to depend to some extent on the kind of checkbox it is.

VBA Code:
Sub SInfo()
    Dim Sh As Shape
    With ActiveSheet
        On Error Resume Next
        For Each Sh In .Shapes
            Select Case Sh.Type
                Case msoFormControl
                    'Form Checkbox
                    Debug.Print "Name: " & Sh.Name
                    Debug.Print "Type:" & Sh.Type
                    Debug.Print "Text : " & Application.WorksheetFunction.Clean(Sh.TextFrame.Characters.Text)
                    Debug.Print "Sh T:" & Sh.Top
                    Debug.Print "Sh H:" & Sh.Height
                    Debug.Print "Sh W:" & Sh.Width
                    Debug.Print "Sh L:" & Sh.Left
                    Debug.Print "Sh BS:" & Sh.BackgroundStyle
                    Debug.Print "Sh OnAction:" & Sh.OnAction
                    Debug.Print "----------------------------"
                 
                Case msoOLEControlObject
                    'ActiveX Checkbox
                    Debug.Print "Name: " & Sh.Name
                    Debug.Print "Type:" & Sh.Type
                    Debug.Print "Caption : " & .OLEObjects(Sh.Name).Object.Caption
                    Debug.Print "Sh T:" & Sh.Top
                    Debug.Print "Sh H:" & Sh.Height
                    Debug.Print "Sh W:" & Sh.Width
                    Debug.Print "Sh L:" & Sh.Left
                    Debug.Print "Sh BS:" & Sh.BackgroundStyle
                    Debug.Print "Sh OnAction:" & Sh.OnAction
                   Debug.Print "----------------------------"
            End Select
        Next Sh
    End With
End Sub

An easy way to find out how to reference a checkbox (or any other object) in VBA is to turn on the Macro Recorder and record yourself doing something (anything) to it. Then study the recorded VBA macro to see how the Macro Recorder referenced it. Also, you then have something to post here if you need clarification.
 
Upvote 0
I also don't have a Mac but on windows Alt+F10 brings up the shapes selection pane, which might be another option worth looking at.

Via the menu, you need to select one of the checkboxes and then in the menu Shape Format > Selection Pane (towards the right hand side - 3rd row)
It will show all the checkboxes by name in descending order of their creation.
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top