userform

  • Thread starter Thread starter Bruce Minty
  • Start date Start date
B

Bruce Minty

G'day Group,
How is a connection from a command button made to a macro.
For instance if I wanted to push a button to run a macro that I created by
using the recorder.
Thanks
Bruce
 
Bruce

The commandbuttons on userforms use events (as do all controls).
Specifically, you want the Click event of the commandbutton. Right-click on
the commandbutton and choose View Code.

Now you have two options (at least). You can paste your recorded code into
the Click event, or you can call your recorded macro from within the event
sub. If you paste, be sure to omit the Sub and End Sub lines from the
recorded macro. The Sub line for event macro is pre-defined and should not
be altered.

To call the recorded macro (let's say it's named macro1), the event sub
would look like this:

Private Sub CommandButton1_Click()
macro1
End Sub
 
Back
Top