Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Reading the ShiftKey state

Is it possible to read the ShiftState from within VBA?

My idea is to create a new menu item in the Data menu and have it ope
one of two possible dialog boxes. (Conceptually this is similar t
what happens when you hold down SHIFT while selecting Edit.) In m
case I wish to use the shift state to force it pop up a user form tha
can be used to modify settings that the user usually would not have an
need to access.

i.e.

Sub data_menu_new_1()

'
'
if ShiftState() Then
UserForm1.Show
else
UserForm2.Show
End If

End Sub

I've played around with KeyDown and KeyPress but it appears that thes
only fire when an actual keyboard (ANSI character) character flow
through the buffer.

Thanks,

Mik

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 218
Default Reading the ShiftKey state

Try:

Public Declare Function GetKeyState _
Lib "user32" (ByVal NVirtKey As Long) As Integer
Public Const VK_SHIFT As Integer = &H10

Sub ReadShiftKey()
If GetKeyState(VK_SHIFT) < 0 Then _
MsgBox "Goodbye" Else MsgBox "Hello"
End Sub

Regards,
Greg

-----Original Message-----
Is it possible to read the ShiftState from within VBA?

My idea is to create a new menu item in the Data menu and

have it open
one of two possible dialog boxes. (Conceptually this is

similar to
what happens when you hold down SHIFT while selecting

Edit.) In my
case I wish to use the shift state to force it pop up a

user form that
can be used to modify settings that the user usually

would not have any
need to access.

i.e.

Sub data_menu_new_1()

'
'
if ShiftState() Then
UserForm1.Show
else
UserForm2.Show
End If

End Sub

I've played around with KeyDown and KeyPress but it

appears that these
only fire when an actual keyboard (ANSI character)

character flows
through the buffer.

Thanks,

Mike


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

.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Reading the ShiftKey state

Declare Function GetKeyState Lib "User32" _
(ByVal vKey As Integer) As Integer

Const SHIFT_KEY = 16
Const CTRL_KEY = 17
Const ALT_KEY = 18

Sub find_key()

'Checks key states to see if both CTRL and ALT Keys are pressed
If GetKeyState(CTRL_KEY) < 0 And GetKeyState(ALT_KEY) < 0 Then
MsgBox "CTRL + ALT KEYS PRESSED"
'Checks key states to see if only CTRL key is pressed
ElseIf GetKeyState(CTRL_KEY) < 0 Then
MsgBox "CTRL KEY PRESSED"
'Checks key states to see if only ALT key is pressed
ElseIf GetKeyState(ALT_KEY) < 0 Then
MsgBox "ALT KEY PRESSED"
'Checks key states to see if only SHIFT key is pressed
ElseIf GetKeyState(SHIFT_KEY) < 0 Then
MsgBox "SHIFT KEY PRESSED"
End If

End Sub

Perform the check at the beginning of your macro. It checks what the key
state is at that time (not when the menu was clicked), but I believe it is
about the best you can do without subclassing Excel.

--
Regards,
Tom Ogilvy


"mjclare " wrote in message
...
Is it possible to read the ShiftState from within VBA?

My idea is to create a new menu item in the Data menu and have it open
one of two possible dialog boxes. (Conceptually this is similar to
what happens when you hold down SHIFT while selecting Edit.) In my
case I wish to use the shift state to force it pop up a user form that
can be used to modify settings that the user usually would not have any
need to access.

i.e.

Sub data_menu_new_1()

'
'
if ShiftState() Then
UserForm1.Show
else
UserForm2.Show
End If

End Sub

I've played around with KeyDown and KeyPress but it appears that these
only fire when an actual keyboard (ANSI character) character flows
through the buffer.

Thanks,

Mike


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



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
replace state names with state code abbreviations se7098 Excel Worksheet Functions 3 July 25th 09 06:41 PM
How can I show state-by-state data (as silos) on a map of NA Rob Charts and Charting in Excel 0 November 5th 07 03:41 PM
state abbreviations gls858 New Users to Excel 7 June 20th 07 09:34 PM
State Map Lost_user Excel Discussion (Misc queries) 0 December 7th 06 04:04 AM
Converting State Names to State Abbreviations aznate Excel Discussion (Misc queries) 1 October 20th 06 06:52 AM


All times are GMT +1. The time now is 07:14 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"