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

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default keypress to fire command button

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default keypress to fire command button

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default keypress to fire command button

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default keypress to fire command button

All sorted - cheer

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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default keypress to fire command button

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default keypress to fire command button

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default keypress to fire command button

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
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
command button add another command Wanna Learn Excel Discussion (Misc queries) 5 December 7th 08 11:42 PM
keypress Garry Jones Excel Programming 2 October 17th 03 09:47 AM
Command Button vs Control Button RGibson Excel Programming 1 October 14th 03 02:24 AM
KeyPress Event Conrado Capistrano Excel Programming 4 September 25th 03 05:27 AM
Command Button vs Form Button T K Excel Programming 4 August 26th 03 07:26 PM


All times are GMT +1. The time now is 06:54 AM.

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"