assign macro using vba

Dharris144

Board Regular
Joined
Jul 22, 2009
Messages
97
i have a sheet with a hundred check boxes. Can someone help with a VBA script to assign the same macro to all checkboxes on current sheet?
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
My apologies for the slow response. This macro will loop through all the form control check boxes on the active sheet and assign their action to a macro titled "Test" in Module1.

Code:
Sub AssignCheckboxMacro()
Dim cb As Shape
  For Each cb In ActiveSheet.Shapes
    If cb.Type = msoFormControl Then
      If cb.FormControlType = xlCheckBox Then
        cb.OnAction = "[COLOR=#ff0000]Module1[/COLOR].[COLOR=#ff0000]Test[/COLOR]"
      End If
    End If
  Next cb
End Sub

You can change the name of the macro and the module name to match your target macro information.
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,045
Members
449,206
Latest member
Healthydogs

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