ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Shortcut (https://www.excelbanter.com/excel-programming/343293-shortcut.html)

Steph[_6_]

Shortcut
 
Is it possible to assign a shortcut keystroke (ie Ctl U) to a sub procedure
if it resides in a private module?



Leith Ross[_67_]

Shortcut
 

Hello Steph,

If by private module you mean a module you inserted into your VB
project then the answer is yes. However, you can only assign a ho
combination that isn't in use. This example calls the Sub (macro
"RunProgram" in such a module. The Sub must be Public for this to work
Place this code in ThisWorkbook under Excel Objects in your project i
the Private Sub WorkBook_Open() procedure.

EXAMPLE
'Assign Keys CTRL + ALT + R to RunProgram Macro
Application.OnKey Key:="%^r", Procedu="RunProgram"

Shift = "+", CTRL = "%", ALT = "^"

To learn more about Key Codes see SendKeys Method in the VB Help.


Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=47770


Jim Thomlinson[_4_]

Shortcut
 
You can not assign a hot key to a private anything. If at the top of your
module you have...

option private module
then everything in the module is hidden adn the scope of everything in the
module is private.

If you have
Private Sub Test
then the scope of this procedure is private and once again you will not be
able to refernece it outside of the module.

By default whether explicitly stated or not everything else is Public. If
however your procedure takes arguments then you will not be able to assign a
hot key.

Public Sub Test
This is public and you can assign a hot key to it. Tools - Macros - Macros
- Options...
--
HTH...

Jim Thomlinson


"Steph" wrote:

Is it possible to assign a shortcut keystroke (ie Ctl U) to a sub procedure
if it resides in a private module?





All times are GMT +1. The time now is 11:21 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com