views:

614

answers:

3

My employer has purchased a third-party tool, OfficeConverter from Conveter Technology that automates the conversion / repair of Office 2003-formatted files to Office 2007 format. This tool also highly automates the translation / change in macro / VBA code requirements between Office 2003 and 2007 formats.

My problem is that during this conversion the tool is opening the targeted Office product, say Excel and is then opening the target user file (ie. Report.xls) and is then examining any VBA / macro code for change requirements. The problem is that IF the Excel file code is dependent upon some external tool like an .OCX file and if that tool doesn't exist on the PC that I'm performing this action on, Excel will pop up a message that the Object has not been found, stopping the entire conversion process (thousands of files in a row) until someone comes along and MANUALLY clicks the appropriate button to close the dialogue box.

I figured that creating a small watching application in VB6 (hey, I'm old and my skills are too) could sit on the same PC and watch for these dialogue boxes and, depending on the specific message, click the appropriate button via the SendMessage API call.

The problem is that I haven't been able to get SendMessage to actually PUSH the button for me, I've tried sending it the Return key value (vbKeyReturn) or even the Space key (vbKeySpace) but the action never results in the dialogue box closing like it should. I can get the focus to tab between whichever buttons on the dialogue box are enabled, but that is about it.

I've attempted to use SendKeys, but that is far less reliable and strongly discouraged in the current documentation that I've come across.

Any suggestions? :)

+3  A: 

If you have the hWnd for the button, and the machine is unattended, you can easily use MouseEvent to move the cursor over the button and click it. This sample includes a drop-in ready module that'll do the dirty work for you given just the window handle:

http://vb.mvps.org/samples/MouseEvent

Otherwise, the most straightforward way is probably to just send WM_LBUTTONDOWN and WM_LBUTTONUP sequentially.

EDIT: If you "just want to get it done" take Jim's advice and try Gary Chanson's Window Demon tool.

Karl E. Peterson
Welcome to Stack Overflow!
MarkJ
Thanks, Mark. Nice concept going here.
Karl E. Peterson
Karl, I have read your articles in VBPJ for YEARS and now you answer *my* question...I feel so lucky! I'm going to give your suggestion a try. Thanks for sharing this!
Ron McMahon
I'm flattered, Ron, truly. And, it would be one of those "fun projects" if you're in tinker mode. But if you "just need to get it done" that Window Demon tool is ready to go. Have fun!
Karl E. Peterson
+2  A: 

Take a look at this utility "Window Demon" by Gary Chanson

Karl: how quickly we forget our pals!

Jim Mack
Yeah, Gary's got some really cool tools. My problem is I rarely look for an existing solution, when it's so much more fun to build one myself. At least for stuff like this. You're right. This one's ideal for this problem!
Karl E. Peterson
The link to the .zip file in the article is dead. I've sent a note to the source site contact to see if the product still exists. It appears to have been removed from the beta area in the site.
Ron McMahon
+1  A: 

I would suggest taking a look at AutoIt.

It is perfect for this task, look for a window with a particular text on it and click a button. Runs in the system tray as a standalone application.

benPearce
Cool! Thanks ben! I haven't head of this...I'll give it a try.
Ron McMahon