Consulting

Results 1 to 5 of 5

Thread: SendInput() in Excel 64Bit

  1. #1
    VBAX Regular k13r4n's Avatar
    Joined
    Nov 2008
    Posts
    31
    Location

    SendInput() in Excel 64Bit

    Hi guys

    Ive been trying to find a solution to this all day and google is failing me!

    At work we have windows 7 and office 2010, both 64Bit.

    ive been working on some code to automaticlly fill in some user forms on the companys ERP system with data from an excel spreadsheet. Everything was going fine, SendKeys was working perfectly, until i tried to send ALT+[Some Key] to open a menu item.

    Turns out that because the ERP system is hosted on a server and is run remotley these key combinations wont pass over with sendkeys (I tested my code with a local application running on the client machine and it works fine so its not my code)

    I then turned to the Keybd_event API call but that again did not work for ALT+ combination.

    My last hope is a SendInput API call but i cant for the life of me get it working at all on 64Bit Office

    Ive had it working at home on my 32Bit Install of Excel

    After a lot of googleing it apears to be somthing to do with how the instructions are stored in memory, but i cant work out how to modify my code.

    here is the Code

    [vba]

    Private Declare PtrSafe Function SendInput Lib "user32" (ByVal nInputs As LongPtr, pInputs As Any, ByVal cbSize As LongPtr) As LongPtr
    Private Declare PtrSafe Function VkKeyScan Lib "user32" Alias "VkKeyScanA" (ByVal cChar As Byte) As Integer

    Private Type KeyboardInput ' creating variable type
    dwType As Long ' input type (keyboard or mouse)
    wVk As Integer ' the key to press/release as ASCSI scan code
    wScan As Integer ' not required
    dwFlags As Long ' specify if key is pressed or released
    dwTime As Long ' not required
    dwExtraInfo As Long ' not required
    dwPadding As Currency ' only required for mouse inputs
    End Type



    ' SendInput constants
    Private Const INPUT_KEYBOARD As Long = 1


    Private Const KEYEVENTF_EXTENDEDKEY As Long = 1
    Private Const KEYEVENTF_KEYUP As Long = 2


    ' Member variables


    Private TheKeys() As KeyboardInput
    Private NEvents As Long




    Sub testage()


    ReDim TheKeys(0 To 3)


    With TheKeys(0)

    .dwType = INPUT_KEYBOARD 'operation type
    .wVk = vbKeyMenu 'press ALT key

    End With


    With TheKeys(1)


    .dwType = INPUT_KEYBOARD ' operation
    type.wVk = VkKeyScan(Asc("f")) 'press chr key

    End With


    With TheKeys(2)

    .dwType = INPUT_KEYBOARD 'operation type
    .wVk = VkKeyScan(Asc("f"))
    .dwFlags = KEYEVENTF_KEYUP 'release chr key

    End With


    With TheKeys(3)


    .dwType = INPUT_KEYBOARD ' operation type
    .wVk = vbKeyMenu
    .dwFlags = KEYEVENTF_KEYUP 'release ALT Key


    End With

    AppActivate "Notepad"
    Sleep 500
    Call SendInput(4, TheKeys(0), Len(TheKeys(0)))


    Erase TheKeys


    End Sub
    [/vba]


    This was working fine on Windows 7 64Bit running Office 32Bit but cant get it working on Office 64Bit, Any ideas??


    Many thanks


    Kieran

  2. #2
    Hi Kieran,

    Use windows scriptin host instead:

    [VBA]Sub test2()
    Dim keys As String
    Dim wsh As Object
    AppActivate "Notepad"
    Application.Wait Now() + TimeValue("00:00:02")
    keys = "%f"
    Set wsh = CreateObject("WScript.Shell")
    wsh.SendKeys keys, True
    Set wsh = Nothing
    End Sub
    [/VBA]
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  3. #3
    VBAX Regular k13r4n's Avatar
    Joined
    Nov 2008
    Posts
    31
    Location
    Hi Jan

    thanks for your response but that doesnt work either

    It works in notepad but not to the ERP app running on our citrix server

    its really anoying becuase normal SendKeys works for sending normal text strings and for sending {ENTER} and {TAB} etc but not for alt + [] combinations




    Kieran

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Try sending an Alt+Shift combo.

  5. #5
    Quote Originally Posted by Jan Karel Pieterse
    Hi Kieran,

    Use windows scriptin host instead:

    [vba]Sub test2()
    Dim keys As String
    ...
    End Sub
    [/vba]
    THANK YOU - THANK YOU - THANK YOU
    THANK YOU - THANK YOU - THANK YOU
    THANK YOU - THANK YOU - THANK YOU
    omg i can't even tell you how much grief that saved me!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •