in vb, what is the 1-line code of assigning a macro using click

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am looking for a sample of the syntax where the macro name and click are on
the vb line.
 
For a control from the forms toolbar:

Activesheet.Buttons(1).OnAction = "MyMacro"
 
sorry, not what i was looking for. let me give you more info. i set up a
command button in excel and would like to assign the macro to the button. if
i right click, assign macro is not listed (not sure why) but if i go to the
vb editor, i would like to type a line in that assigns the macro to the
button. i seem to recall that it would have the button object, macro name
and click on one line. i also recall that it is very simple and a basic
statement.
 
I gave you the code to assign a macro to a button from the forms toolbar.
However, Command buttons from the control toolbox toolbar are not assigned to
macros. They have build in events. To get to the Click event for the
Commandbutton, right click on the sheet tab that contains the button and
select view code. In the resulting sheet module, at the top of the module,
in the left dropdown select Commandbutton1 (or the name of your command
button) and in the right dropdown select Click.

YOu will get the event

Private Sub CommandButton1_Click()

End sub

You can put your code in this procedure/event. (including a call to a macro
in a general module).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top