15

I am trying to use the SendKeys() command to another window with my VB6 app.

What I wanted is to click a button, and then have 10 seconds to go to the other window before the app sends some keys to that window. I got everything sorted but for some reason when I call something like this:

SendKeys ("A")

I get this error:

Run-time error '70':

Permission denied

Does anyone know a way around this? Thanks.

1
  • If you're on Vista this might be caused by user-account control (UAC). You can workaround by turning off UAC. Feb 21, 2010 at 22:57

9 Answers 9

22

For Windows 7: Change the UAC settings to never notify.

For Windows 8 and 10:
Add this method to any module:

Public Sub Sendkeys(text as variant, Optional wait As Boolean = False)
   Dim WshShell As Object
   Set WshShell = CreateObject("wscript.shell")
   WshShell.Sendkeys cstr(text), wait
   Set WshShell = Nothing
End Sub 

It's worked fine for me in windows 10.

1
  • This is the only thing that worked for me!
    – xyz333
    Aug 25, 2022 at 15:34
8

Take a look at what Karl Peterson worked up as a fix for this under Vista:

SendInput

0
6

Replacement for VB6 SendKeys is WScript.Shell SendKeys, like this:

Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "1{+}"

See MSDN for help.

6

In a public Module add:

Public Sub Sendkeys(text$, Optional wait As Boolean = False)
    Dim WshShell As Object
    Set WshShell = CreateObject("wscript.shell")
    WshShell.Sendkeys text, wait
    Set WshShell = Nothing
End Sub

This will "overwrite" SendKeys Function

4

On Windows 7:

  • Open the Control Panel
  • Change user account control setting
  • Change to NEVER NOTIFY
  • Restart the computer
2

Delete "msvbvm60.dll" File From The Application

Follow The Following Step

  1. Right Click On The Application .Exe File And Click On Property
  2. Click On Compatibility Tab
  3. Click On Run This Program in Compatibility Mode And Chose Windows Xp SP2 From It.
  4. Click On Run This Program As Administrator
  5. Click On Apply Than Ok.
  6. Delete The "msvbvm60.dll" From The Application Folder.

All Done, Now Your Application Start Running Without Any Error Like Access Denied

0
1

the problem is about vb6 IDE and windows desktop context menu and you will do as described in here :

http://www.vbforums.com/showthread.php?747425-SendKeys-and-Windows-8

and main reference is here :

http://www.vbforums.com/showthread.php?745925-RESOLVED-How-to-trigger-the-desktop-context-menu

1

You can use this code in Module

Public Sub SendKeyTab(CForm As Form)
On Error Resume Next
Dim G As Single
For G = 0 To CForm .Controls.Count - 1
    If CForm .Controls(G).TabIndex = CForm .ActiveControl.TabIndex + 1 Then CForm .Controls(G).SetFocus
Next
End Sub

On Each Form Level

If KeyCode
1

Use this API:

Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

and

keybd_event keycode, 0, 0, 0  'KEY DOWN
keybd_event keycode, 0, KEYEVENTF_KEYUP, 0 'KEY UP

when key code is 32 for space, 35 for keyend, 8 for vbKeyBack, etc.

1
  • Welcome to SO! Try to provide more explanation to your answers along with better formatting. See How to answer page for help in improving your answer.
    – Madness
    Aug 17, 2015 at 18:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.