×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Running a macro through a command button

Running a macro through a command button

Running a macro through a command button

(OP)
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

RE: Running a macro through a command button

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

RE: Running a macro through a command button

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

RE: Running a macro through a command button

(OP)
Thanks, that solved my problem. (i had to many "End"s)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close