Hi,
My problem is that I am trying to write a macro in vba/excel that will take a list of "part #'s" (6 Digits) from a worksheet and paste it to a non-office application. I have managed to paste the number's to the correct text box field using a pasteforeignwindow command(api user32 handles). What I cannot seem to accomplish is selecting items within a combobox. I tried pasting the required value to the text box but it crashes the application upon updating. I managed (with the code below) to select the item, however when I focus back to the application (from vba)the value of the box resets to the default value.
The set cursor command selects the item but doesn't "mouse down"....
I am going insane trying to figure this out.. I was thinking if I could send key commands after the "mouse" highlights the box, that would work too.. but have been unsuccessful in sending keys to handles...and I know the handles are correct..
If anyone has any idea's I would greatly appreciate them.
Thank you!!
My problem is that I am trying to write a macro in vba/excel that will take a list of "part #'s" (6 Digits) from a worksheet and paste it to a non-office application. I have managed to paste the number's to the correct text box field using a pasteforeignwindow command(api user32 handles). What I cannot seem to accomplish is selecting items within a combobox. I tried pasting the required value to the text box but it crashes the application upon updating. I managed (with the code below) to select the item, however when I focus back to the application (from vba)the value of the box resets to the default value.
Code:
'CODE...(in a module)
Public Sub ComboBox()
Dim thunderrtmdiform As Long, mdiclient As Long, thunderrtformdc As Long
Dim thunderrtpictureboxdc As Long, thunderrtcombobox As Long
thunderrtmdiform = FindWindow("thunderrt6mdiform", vbNullString)
mdiclient = FindWindowEx(thunderrtmdiform, 0&, "mdiclient", vbNullString)
thunderrtformdc = FindWindowEx(mdiclient, 0&, "thunderrt6formdc", vbNullString)
thunderrtpictureboxdc = FindWindowEx(thunderrtformdc, 0&, "thunderrt6pictureboxdc", vbNullString)
thunderrtpictureboxdc = FindWindowEx(thunderrtformdc, thunderrtpictureboxdc, "thunderrt6pictureboxdc", vbNullString)
thunderrtpictureboxdc = FindWindowEx(thunderrtpictureboxdc, 0&, "thunderrt6pictureboxdc", vbNullString)
thunderrtcombobox = FindWindowEx(thunderrtpictureboxdc, 0&, "thunderrt6combobox", vbNullString)
Dim LIndex As Long
LIndex = 2 ' item to select
Call SendMessageLong(thunderrtcombobox, CB_SETCURSEL, LIndex, 0&)
End Sub
The set cursor command selects the item but doesn't "mouse down"....
I am going insane trying to figure this out.. I was thinking if I could send key commands after the "mouse" highlights the box, that would work too.. but have been unsuccessful in sending keys to handles...and I know the handles are correct..
If anyone has any idea's I would greatly appreciate them.
Thank you!!