简体   繁体   English

如何将VB6应用程序的点击或键发送到Excel对话框?

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

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. 我的雇主从Conveter Technology购买了第三方工具OfficeConverter,该工具可以自动将Office 2003格式的文件转换/修复为Office 2007格式。 This tool also highly automates the translation / change in macro / VBA code requirements between Office 2003 and 2007 formats. 此工具还可以高度自动化地在Office 2003和2007格式之间转换/更改宏/ VBA代码要求。

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. 我的问题是,在此转换过程中,该工具正在打开目标Office产品(例如Excel),然后正在打开目标用户文件(即Report.xls),然后正在检查任何VBA /宏代码的更改要求。 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. 问题在于,如果Excel文件代码依赖于某些外部工具(如.OCX文件),并且如果我在执行此操作的PC上不存在该工具,则Excel将弹出一条消息,指出对象具有找不到,请停止整个转换过程(连续几千个文件),直到有人出现并手动单击相应的按钮以关闭对话框。

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. 我认为可以在VB6中创建一个小型监视应用程序(嘿,我已经老了,我的技能也很强)可以坐在同一台PC上并监视这些对话框,然后根据特定消息,通过SendMessage单击相应的按钮。 API调用。

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. 问题是我无法让SendMessage真正为我按下按钮,我尝试向其发送回车键值(vbKeyReturn)甚至是空格键(vbKeySpace),但操作从未导致对话盒子应该关闭。 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. 我曾尝试使用SendKeys,但是在我所遇到的当前文档中,这远不够可靠,并且不建议使用。

Any suggestions? 有什么建议么? :) :)

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. 如果按钮具有hWnd,并且机器无人看管,则可以轻松地使用MouseEvent将光标移至按钮上并单击。 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 http://vb.mvps.org/samples/MouseEvent

Otherwise, the most straightforward way is probably to just send WM_LBUTTONDOWN and WM_LBUTTONUP sequentially. 否则,最直接的方法可能就是依次发送WM_LBUTTONDOWNWM_LBUTTONUP

EDIT: If you "just want to get it done" take Jim's advice and try Gary Chanson's Window Demon tool. 编辑:如果您“只是想把它做好”,请听吉姆的建议,然后尝试加里·钱森的“ 窗口恶魔”工具。

Take a look at this utility "Window Demon" by Gary Chanson 看看Gary Chanson的这个实用程序 “ Window Demon”

Karl: how quickly we forget our pals! 卡尔:我们有多快忘记了我们的朋友!

I would suggest taking a look at AutoIt . 我建议看看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. 作为独立应用程序在系统托盘中运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM