VBA GetKeyState not working?

Peter h

Active Member
Joined
Dec 8, 2015
Messages
417
I can't seem to get this to work. I'm wondering if there is a preference that I need to turn on or something, but not sure. Can anyone give me any help?

Code:
Private Declare PtrSafe Function GetKeyState Lib "USER32" (ByVal nVKey As Long) As Integer

I'm getting a Run-Time Error 453: Cannot find DLL entry point GetKeyState in USER32
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Which version of Windows are you running?
 
Upvote 0
Try importing the function by its ordinal number and see if it works for you.

For office 32 bit :
Code:
Declare PtrSafe Function GetKeyState Lib "user32" Alias "[COLOR=#ff0000]#1865[/COLOR]" (ByVal nVirtKey As Long) As Integer

For office 64 bit:
Code:
Declare PtrSafe Function GetKeyState Lib "user32" Alias "[COLOR=#ff0000]#1866[/COLOR]" (ByVal nVirtKey As Long) As Integer
 
Last edited:
Upvote 0
Try importing the function by its ordinal number and see if it works for you.

For office 32 bit :
Code:
Declare PtrSafe Function GetKeyState Lib "user32" Alias "[COLOR=#ff0000]#1865[/COLOR]" (ByVal nVirtKey As Long) As Integer

For office 64 bit:
Code:
Declare PtrSafe Function GetKeyState Lib "user32" Alias "[COLOR=#ff0000]#1866[/COLOR]" (ByVal nVirtKey As Long) As Integer

This worked. Thank you so much.
 
Upvote 0

Forum statistics

Threads
1,223,954
Messages
6,175,603
Members
452,660
Latest member
Zatman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top