Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running a macro through a command button

Status
Not open for further replies.

farnye

Civil/Environmental
May 22, 2003
14
0
0
US
I'm having problems getting this to work. Do you just use a simple run command in the command button code?

I basically want to click a given button and the macro will start.
 
Replies continue below

Recommended for you

The easiest way I know how to do it is write your macro first. Next, insert your control button and then double click on it (that should open the VBA editor window). Next, copy the macro you wrote (excluding the "Sub" and "end" lines) and paste it in the command button sub proceedure. Then just exit the design mode (in excel) and you should be able to execute the macro by clicking you button. Alternately (as long as you know the name of your cammand button), you can just re-name your sub proceedure from:

Sub MyMarco() to Sub CommandButton1_Click()

but this will only work if the command button is named "CommandButton1". If you get stuck, search the help.

Good Luck!

jproj
 
When I create a button, a box pops up asking if I want to assign a macro. Or right-click an existing button and select 'assign macro.' Then assign existing code or create new code with the name suggested.

Patrick
 
Status
Not open for further replies.
Back
Top