Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
How do i assign the "q" key to operate my "commandbutton1" code?
Do i need to assign the same code to the "q" key, if so how again -- Message posted from http://www.ExcelForum.com |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
mikewild2000,
How do i assign the "q" key to operate my "commandbutton1" code? Can't be done. but............................... Create a new macro in a regular module. For arguments sake, name it "MyCommButtCode" Now cut and paste everything in the CommandButton1 code (between the Sub & End Sub) and paste it into this new sub. In the CommandButton1 code, call the new sub Private Sub CommandButton1_Click() MyCommButtCode End Sub Now, from the VBA editor in the Immediate window, type the following: Application.MacroOptions Macro:="MyCommButtCode", Description:="", ShortcutKey:="q" and then press <enter. Even a little easier................ Record a macro (any name) and assign the shortcut key. Delete the code in that macro, replace it with your CommandButton code and then just call that macro from your CommandButton. John "mikewild2000 " wrote in message ... How do i assign the "q" key to operate my "commandbutton1" code? Do i need to assign the same code to the "q" key, if so how again? --- Message posted from http://www.ExcelForum.com/ |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
It is a workaround.
But what about copying the code and assigning a keypress event to it? Is that possiable. --- Message posted from http://www.ExcelForum.com/ |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
mikewild2000,
It is a workaround. That it is and since it wasn't what you were looking for, I dug a little deeper. First of all, forget all that drivel I wrote about moving code around. I don't know why, but the following did, in fact, run the CommandButton_Click code (Excel 2000): ActiveSheet.CommandButton1.Value = True The above is assuming that you have the CommandButton on a worksheet and that it was created from the Controls Toolbox. Create a macro with your shortcut key assigned and use the code above in that macro to "press" the button. Is that any closer to what you need?? John "mikewild2000 " wrote in message ... It is a workaround. But what about copying the code and assigning a keypress event to it? Is that possiable. --- Message posted from http://www.ExcelForum.com/ |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Another way is to call the procedure.
I had this under sheet1 (and sheet1 is the codename of the worksheet): Option Explicit Sub CommandButton1_Click() MsgBox "hi there" End Sub (notice that it doesn't have "private" in front of the Sub statement. And in a general module: Option Explicit Sub test() Call Sheet1.CommandButton1_Click End Sub "mikewild2000 <" wrote: It is a workaround. But what about copying the code and assigning a keypress event to it? Is that possiable. --- Message posted from http://www.ExcelForum.com/ -- Dave Peterson |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks Dave - I got their in the end by copy/paste my code from the
command buttons into seperate macros. Then using workbook_open() poped in the onkey statements so that the shortcut keys work. Not bad for a novice? --- Message posted from http://www.ExcelForum.com/ |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If it's working, you've lost the novice label.
"mikewild2000 <" wrote: Thanks Dave - I got their in the end by copy/paste my code from the command buttons into seperate macros. Then using workbook_open() poped in the onkey statements so that the shortcut keys work. Not bad for a novice? --- Message posted from http://www.ExcelForum.com/ -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
command button add another command | Excel Discussion (Misc queries) | |||
keypress | Excel Programming | |||
Command Button vs Control Button | Excel Programming | |||
KeyPress Event | Excel Programming | |||
Command Button vs Form Button | Excel Programming |