Just out of curiosity...
You can identify individual keyboard modifiers by using the following constants:
Constant Value Description
fmShiftMask 1 Mask to detect SHIFT.
fmCtrlMask 2 Mask to detect CTRL.
fmAltMask 4 Mask to detect ALT.
Those constants don't seem to be exist in "my" VBA (Excel 2002/10/XP) - no matches in the object browser, "variable not defined" when used in code. Could people verify that in other copies and versions?
Look just under Figure 1. (http://msdn.microsoft.com/en-us/library/aa155610(office.10).aspx) Looks like a KeyDown returned argument. Check out the VBA help file (I use Office '97) titled: "KeyDown, KeyUp Events" or the VB6 help file titled: "Detecting SHIFT, CTRL, and ALT States"
So, does '97's VBA actually have the constants, then? :confused:
My help for the Key events specifies the parameter as
ByVal Shift As fmShiftState
but when I implement the handler using the dropdowns it gives me
ByVal Shift As Integer
and the object browser is just as unaware of the fmShiftState enum as it is of its member consts.
Ah, well ... :-\
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
End SubIn Excel '97 I get 16 and 1 for Shift, 17 and 2 for Ctrl and 18 and 4 for Alt.
Thank you Micro$oft!
Okay, but you don't have the defined constants either, yes?
Sorry to be persistent... :p
If you mean the Object Browser doesn't recognize fmShiftMask, fmCtrlMask or fmAltMask, no they're not in the list of recognized constants. I can't pull a value for them in the immediate window either.
Persistence is a virtue in the world of programming.
Yes, that's what I wanted to know. Thanks! :)
06-01-2008, 08:47 AM
Just FYI it's the same for me in Excel 2007. :)
I pretty much expected that. The most reasonable explanation is that the constants were "lost" in some VBA version change and the help not updated, it seems to me.
The first Excel version supporting VBA was apparently 5.0 in '93, meaning the VBA version would have been based on VB3. I don't suppose anyone would like to install Windows 3.1 and Excel 5 just to check, eh? :p