Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Assign button to run macro

2 views
Skip to first unread message

jamie85 <>

unread,
Feb 2, 2004, 2:21:05 PM2/2/04
to
How can i assign a button to run a macro?


---
Message posted from http://www.ExcelForum.com/

pikus <>

unread,
Feb 2, 2004, 2:26:16 PM2/2/04
to
In ThisWorkbook:

Application.OnKey "{F1}", "UnHide"

Where "F1" is the button you're assigning the macro to and "UnHide" is
the name of the macro. Lookup "OnKey" in VBA Help for a list of the
keys names to use. - Pikus

jamie85 <>

unread,
Feb 2, 2004, 2:34:42 PM2/2/04
to
I have this:

Private Sub CommandButton1_Click()
Application.OnKey "{CommandButton1}", "Macro1"
End Sub

However it isn't working. Any idea why?

Ron de Bruin

unread,
Feb 2, 2004, 2:36:23 PM2/2/04
to
You can use two sort of buttons

View>Toolbars in the Menu bar
Check Forms or Control Toolbox


On a button from the Forms Toolbar you can right click and assign a macro

If you have a button from the Control Toolbox
Press the first button on the Control Toolbox toolbar to go into the design mode
Double click on the button you placed on your worksheet.
The VBA editor will open with this

Private Sub CommandButton1_Click()

End Sub

You can place the code in the event or place the macroname in the event.
Press Alt-q to go back to Excel and press the first button on the Control Toolbox again to exit the design mode

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl

"jamie85 >" <<jamie85...@excelforum-nospam.com> wrote in message news:jamie85...@excelforum-nospam.com...

Bill Kuunders

unread,
Feb 2, 2004, 2:42:55 PM2/2/04
to
Or you can just insert a picture or drawing which can be formatted not to
print,
and assign a macro to it by right clicking on the border and select "assign
macro............."
The drawing can be a simple square or circle.
regards
Bill K
"pikus >" <<pikus....@excelforum-nospam.com> wrote in message
news:pikus....@excelforum-nospam.com...

pikus <>

unread,
Feb 2, 2004, 2:40:36 PM2/2/04
to
CommandButton1 is to a key. If you want a key on your keyboard to call
the macro you need to use the name of that key. Looking up OnKey in
Help will give you a good list to use, though it isn't exhaustive. If
however you want a button to run some code, enter design mode and right
click and select "View Code" from the menu. Just paste the code itself
into the window that pops up or you can call the macro using "Call".

Private Sub CommandButton1_Click()
Call Macro1
End Sub

Let me know if you have any more problems. - Pikus

RogerDaShrubber <>

unread,
Feb 2, 2004, 2:44:06 PM2/2/04
to
jamie85 wrote:
> *How can i assign a button to run a macro? *

right click on the grey tool bar at the top and pick the "Forms"
toolbar.

it will open a toolbar with a bunch of things you can add to your
sheet

select the button (looks like a grey rectangle) and then click on the
worksheet and that should add a button to your worksheet.

And it will ask you to assign a macro. Select the one you want with
that button, and then say "OK"

you can change the Caption and size. If this doesn't work let me know,
I just had to figure this out recently.

Tom Ogilvy

unread,
Feb 2, 2004, 3:28:53 PM2/2/04
to
Pikus,
The OP never mentioned the word Key. In his original post he asked about
assigning a macro to a button. You are the one that described how to run a
macro from a shortcut key.

--
Regards,
Tom Ogilvy

"pikus >" <<pikus....@excelforum-nospam.com> wrote in message
news:pikus....@excelforum-nospam.com...

pikus <>

unread,
Feb 3, 2004, 8:44:22 AM2/3/04
to
You're right Tom. Sorry all. - Pikus
0 new messages