How can I send clicks or keys from a VB6 app to an Excel dialog box?

社会主义新天地 提交于 2019-12-11 15:02:58

问题


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? :)


回答1:


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.




回答2:


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

Karl: how quickly we forget our pals!




回答3:


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.



来源:https://stackoverflow.com/questions/978557/how-can-i-send-clicks-or-keys-from-a-vb6-app-to-an-excel-dialog-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!