Macro and Form
Macro and Form
1
VBA Code @Excel
1 2
Assign a macro to a Form or a Control button
• On the Developer tab, in the Controls group, click Insert, and then under
Form Controls, click Button Button image .
• Click the worksheet location where you want the upper-left corner of the
button to appear. The Assign Macro popup window appears.
• To specify the control properties of the button, right-click the button, and
then click Format Control.
1 4
Add a command button (ActiveX control)
1 5
Add a command button (ActiveX control)
4.In the subprocedure for the command button, do either of the following:
5.Enter the name of an existing macro in the workbook. You can find macros by clicking Macros in
the Code group. You can run multiple macros from a button by entering the macro names on separate
lines inside the subprocedure.
6.As necessary, add your own VBA code.
7.Close the Visual Basic Editor, and click Design Mode Button image to ensure design mode is off.
8.To run the VBA code that is now part of the button, click the ActiveX command button that you
just created.
9.To edit the ActiveX control, make sure that you are in design mode. On the Developer tab, in the
Controls group, turn on Design Mode.
10. To specify the control properties of the command button, on the Developer tab, in the Controls
group, click Properties Button image . You can also right-click the command button, and then click
Properties. 6
References
• https://www.youtube.com/watch?v=AByFH0TN53M
• https://support.microsoft.com/en-us/office/assign-a-macro-to-a-form-or-a-control-
button-d58edd7d-cb04-4964-bead-9c72c843a283
1 7
Thank you
8