Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Assign button to run macro

How can i assign a button to run a macro?


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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Assign button to run macro

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


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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Assign button to run macro

I have this:

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

However it isn't working. Any idea why?


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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Assign button to run macro

You can use two sort of buttons

ViewToolbars 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 " wrote in message ...
How can i assign a button to run a macro?


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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Assign button to run macro

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


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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 303
Default Assign button to run macro

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 " wrote in message
...
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


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



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Assign button to run macro

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.


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

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Assign button to run macro

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 " wrote in message
...
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


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



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Assign button to run macro

You're right Tom. Sorry all. - Piku

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create A Button and Assign A Macro To It carl Excel Worksheet Functions 2 November 8th 11 08:30 PM
Assign a macro to a button totofab Excel Discussion (Misc queries) 4 December 13th 07 06:16 PM
Assign a macro to a command button SheriTingle Excel Discussion (Misc queries) 4 September 25th 06 06:38 PM
How do I Assign Macro to a button? BellExcel Charts and Charting in Excel 4 May 20th 05 07:21 PM
Assign Macro to Command Button Shunt Excel Programming 1 August 7th 03 02:07 PM


All times are GMT +1. The time now is 08:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"