Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA/API Excel - Combo Box Selection - Non Office Application 1

Status
Not open for further replies.

Greybush

Technical User
Oct 21, 2009
2
CA
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.

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!!
 


Hi,
What I cannot seem to accomplish is selecting items within a combobox.
If anyone has any idea's I would greatly appreciate them.
What are the Properties & Methods of this control?

You have to know this application's Object Model. Have you researched this?

What non-office application is it? There may be members who have had experience with this application.

Please answer ALL the questions I have posed above.


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
You might want to have a look into CBN_SELCHANGE windows message (this generates the click event for combo controls which doesn't fire if you just use CB_SETCURSEL).

There's also some pretty nasty hacks you could do sending KEY_UP/KEY_DOWN messages but I'd certainly try my first suggestion beofre resorting to that kind of thing! [wink]

Hope this helps

Andy
---------------------------------
[green]' Signature removed for testing purposes.[/green]

 
The Combobox has 5 values: add, change, delist, recovery, and relist. It's weird, it has three handles. I am trying to select relist and delist. A textbox handle, a combobox handle and another handle for the dropdown. It's an older program, created specifically for the company I work for. All of the comboboxes have the same handle# and class name, so I have to store the handle # and call that.

I've tried implimenting CBN_SELCHANGE, but have been unsuccessful. Not sure how it works. Harley could you explain it a little more?

Thanks for the help!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top