Hi all,
I'm having an issue with a macro I wrote to get an ID from a third-party product. I need the ID from the third-party screen (form) to figure out which record I'm on, because there is no data layer in the SDK. Basically, I created a DLL that adds an option to the product's menu. When the user clicks the new option on the menu, the program moves the cursor (using Alt-G) to the first field on the form, then "presses" Ctrl-C. This works great if it is isolated--I can use ctrl-v to paste the contents of the ID field after it runs. However, as soon as I add anything else to it, like MsgBox Clipboard.GetText, for example, it doesn't work. Since my whole reason to do the "macro" exercise is to capture the info in the clipboard, I really need to fix this. Code follows, but please read my last comment, below.
The code is here in a sub of a Functions.bas module:
Clipboard.Clear
' Alt-G:
Call keybd_event(vbKeyMenu, 0, 0, 0)
Call keybd_event(vbKeyG, 0, 0, 0)
Call keybd_event(vbKeyG, 0, KEYEVENTF_KEYUP, 0)
Call keybd_event(vbKeyMenu, 0, KEYEVENTF_KEYUP, 0)
Call keybd_event(vbKeyControl, 0, 0, 0)
' Ctrl-C:
Call keybd_event(vbKeyC, 0, 0, 0)
Call keybd_event(vbKeyC, 0, KEYEVENTF_KEYUP, 0)
Call keybd_event(vbKeyControl, 0, KEYEVENTF_KEYUP, 0)
And in the Globals:
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
And in the declarations of the Functions module:
Declare Function apiFindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpclassname As Any, ByVal lpCaption As Any) As Long
Final Comment:
I noticed that when it works (if it runs by itself without any code after it), my cursor is where it should be -- in the ID field -- and the whole field is selected. When I run it with my "msgbox" command (or any command) after it, the focus is not on the ID field. I'm not sure if this matters but I figured I'd include it in case it helps.
Thanks,
jr
If the variable assignment removes the item from the clipboard, you can add it back to the clipboard.
Question: Have you considered SendMessage() API or SendKeys, rather than keybd_event() API?