Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send keys problem 1

Status
Not open for further replies.

bustersports

Programmer
Sep 25, 2002
92
0
0
US
I am having problems with the SendKey function in Vista Home Premium. It works fine in XP or XP Pro.

This code generates an error that "The SendKeys action requires "program name" Utility Add-In to be loaded." No idea what they are talking about.
Function Macro2()
On Error GoTo Macro2_Err
SendKeys "F1", False
Macro2_Exit:
Exit Function
Macro2_Err:
MsgBox Error$
Resume Macro2_Exit
End Function

If I just try this code, I get a run-time error '70': Permission Denied error.

SendKeys "{F1}"

They only occur on the Vista machine. I cannot see anything that is obvious. Any clues from anyone?

Thanks very much in advance.
 
I assume F1 is still the help key in Vista for access help. Does pressing F1 work as you would expect?

Mark Davies
Warwickshire County Council
 
mdav2

Yes the F1 does help. The same error occurs no matter what the sequence of keys are. I am using SendKeys in a couple of places with different keystrokes, but all have the same result, again only on a Vista machine. Weird to me.
 
I have read that un-installing and re-installing Office can solve this type of problem.
 
this is because Vista doesn't recognize the SendKeys used by previous versions. I got this from the web, and altered it to call the F11 key.


Option Compare Database

Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal code As Long, ByVal maptype As Long) As Long
Declare Function VkKeyScan Lib "user32" Alias "VkKeyScanA" (ByVal c As Byte) As Integer
Declare Sub keybd_event Lib "user32" (ByVal vk As Byte, ByVal scan As Byte, ByVal Flags As Long, ByVal extra As Long)
Sub MySendKeys(Key As String)
'Uses Windows API to duplicate the Sendkeys function for
'a single CTRL+k combination. (Vista problem)
Dim keyvk As Integer
Dim keyscan As Integer
Dim ctlscan As Integer

keyvk = VkKeyScan(Asc(Key)) And &HFF
keyscan = MapVirtualKey(keyvk, 0)
ctlscan = MapVirtualKey(vbKeyControl, 0)

'Call keybd_event(vbKeyControl, ctlscan, 0, 0) 'Ctrl down
Call keybd_event(keyvk, keyscan, 0, 0) 'Key down
Call keybd_event(keyvk, keyscan, &H2, 0) 'Key up
' Call keybd_event(vbKeyControl, ctlscan, &H2, 0) 'Ctrl up

End Sub

Sub MySendKeysF11()
Call keybd_event(vbKeyF11, keyscan, 0, 0) 'Key down
Call keybd_event(vbKeyF11, keyscan, &H2, 0) 'Key up
End Sub



HTH
PaulF
 
PaulF

Thanks very much, will give it a try.

Remou,

I tried the uninstall, did not solve it, but thanks for thre response.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top