For my code to work you have to setup the "hooks" for the keys (run
'MapNumKeys') in order for them to use the 'MoveCursor' procedure.
Actually, the names of the 2 procs in my project were...
Sub ToggleKeyHooks(sKeys$, Optional Reset As Boolean = False)
and
Sub ToggleMenuHooks(sMenus$, Optional Reset As Boolean = False)
...but I changed this in my post to follow the context of Praga Mike's
post. Reason is that not too many people are familiar with the
terminology relating to "hooking" built-in menus/keypress actions and
diverting them to run custom procedures. That said, here's the complete
code...
Sub ToggleKeyHooks(sKeys$, Optional Reset As Boolean = False)
' Hooks keyboard actions to run custom code.
' Restores keyboard actions to normal when True is passed in.
Dim vKeys, vKey, n&
vKeys = Split(sKeys, ",")
With Application
For n = LBound(vKeys) To UBound(vKeys)
vKey = Split(vKeys(n), "|")
If Reset Then .OnKey vKey(0) Else .OnKey vKey(0), vKey(1)
Next 'n
End With 'Application
End Sub 'ToggleKeyHooks
Sub ToggleMenuHooks(sMenus$, Optional Reset As Boolean = False)
' Hooks built-in menus to run custom code
' Restores menus to normal when True is passed in.
Dim vMenus, vMenu, n&
vMenus = Split(sMenus, ",")
For n = LBound(vMenus) To UBound(vMenus)
vMenu = Split(vMenus(n), "|")
With Application.CommandBars(vMenu(0))
If Reset Then .Reset Else .OnAction = vMenu(1)
End With 'Application.CommandBars
Next 'n
End Sub 'ToggleMenuHooks
...which I've been using for quite some time. I store these in a module
nameD "mMenus" which I can import to any project and modify to suit.
The underlying mechanism is to store predefined params as delimited
strings...
Public sKEY_HOOKS$ = "0|Zero,1|One,2|Two,3|Three,4|Four," _
& "5|Five,6|Six,7|Seven,8|Eight,9|Nine"
Public sMENU_HOOKS$ = "Save|HookSave,SaveAs...|HookSaveAs"
..where items are stored as 'value pairs', and used as follows...
Sub Aut
pen()
' Contains startup code
Call InitGlobals: StoreExcelSettings: SetupUI
Call ToggleKeyHooks(sKEY_HOOKS): ToggleMenuHooks sMENU_HOOKS
CreateMenus
End Sub 'Aut
pen
Sub Auto_Close()
' Contains shutdown/cleanup code
Call RestoreExcelSettings: ToggleKeyHooks sKEY_HOOKS, True
Call ToggleMenuHooks(sMENU_HOOKS, True): DeleteMenus
End Sub 'Auto_Close
What makes this nice is that I can send any other params I need/want to
change in context to the current user activity. For example, if I want
to temporarily hook the built-in 'Print' menu (on-the-fly) then...
Call ToggleMenuHooks("Print...|HookPrint") '//hook the menuitem
'do special printing via normal .PrintOut method (and its params)
Call ToggleMenuHooks("Print...|", True) '//reset the menuitem
...as the procs are generic and so don't need to know what's going on
beyond the scope of the params they're passed.
I mostly use just use ToggleKeyHooks for disabling the usual keyboard
shortcuts to open the VBE window, and access any part of the UI I don't
want users to get to. (Most my stuff uses its own instance of Excel
that I automate via a VB6.exe frontloader. Thus, I customize the UI
however I want. The end result is an app that doesn't give much hint
its user is working with Excel<g>)
--
Garry
Free usenet access at
http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion