Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
Showing results for 
Search instead for 
Did you mean: 
Active Contributor
In context of the posting from mic jones here I check different ways of SendKey from an Excel VBA application to a session window.

At first I identfiy the handle of the session window and set it in foreground with the following code
Private Declare Function SetForegroundWindow Lib "user32.dll" _
(ByVal hWnd As Long) As Long

hWnd = Session.ActiveWindow.Handle
SetForegroundWindow hWnd


After that I use different methods of SendKeys:

  1. Standard VBA SendKeys, but it doesn't work.SendKeys "+{DOWN}", True 

  2. SendKeys via SendMessage, but it doesn't work.Private Declare Function SendMessageA Lib "user32.dll" _
      (ByVal hWnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long

    SendMessageA hWnd, &H100, vbKeyShift, 0
    SendMessageA hWnd, &H100, vbKeyDown, 0
    SendMessageA hWnd, &H101, vbKeyDown, 0
    SendMessageA hWnd, &H101, vbKeyShift, 0

  3. SendKeys via keybd_event, but it doesn't work.Private Declare Sub keybd_event Lib "user32.dll" _
      (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

    keybd_event &H10, 0, 0, 0
    keybd_event &H28, 0, 0, 0
    keybd_event &H28, 0, 2, 0
    keybd_event &H10, 0, 2, 0 

  4. SendKeys via Windows Scripting Host and this works very fine.Dim wsh As WshShell
    Set wsh = CreateObject("WScript.Shell")
    wsh.SendKeys "+{DOWN}"

Maybe someone can use this information or show different ways.
Labels in this area