k13r4n
08-28-2011, 08:39 PM
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
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
This was working fine on Windows 7 64Bit running Office 32Bit but cant get it working on Office 64Bit, Any ideas??
Many thanks
Kieran
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
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
This was working fine on Windows 7 64Bit running Office 32Bit but cant get it working on Office 64Bit, Any ideas??
Many thanks
Kieran