如何将 VB6 应用程序中的点击或按键发送到 Excel 对话框?
我的雇主从 Conveter Technology 购买了第三方工具 OfficeConverter,该工具可以自动将 Office 2003 格式的文件转换/修复为 Office 2007 格式。 该工具还可以高度自动化 Office 2003 和 2007 格式之间宏/VBA 代码要求的转换/更改。
我的问题是,在此转换过程中,该工具将打开目标 Office 产品(例如 Excel),然后打开目标用户文件(即 Report.xls),然后检查任何 VBA/宏代码以了解更改要求。 问题是,如果 Excel 文件代码依赖于某些外部工具(例如 .OCX 文件),并且如果我正在执行此操作的 PC 上不存在该工具,Excel 将弹出一条消息,指出该对象已存在没有找到,停止整个转换过程(连续数千个文件),直到有人出现并手动单击相应的按钮关闭对话框。
我想在 VB6 中创建一个小型观看应用程序(嘿,我老了,我的技能也太高了)可以坐在同一台 PC 上观看这些对话框,然后根据具体消息,通过 SendMessage 单击相应的按钮API 调用。
问题是我无法让 SendMessage 真正为我按下按钮,我尝试向其发送 Return 键值(vbKeyReturn)甚至空格键(vbKeySpace),但该操作永远不会导致对话盒子像它应该的那样关闭。 我可以将焦点放在对话框上启用的任何按钮之间的选项卡上,但仅此而已。
我尝试过使用 SendKeys,但它的可靠性要差得多,并且在我遇到的当前文档中强烈建议不要这么做。
有什么建议么? :)
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? :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您有按钮的 hWnd,并且机器无人值守,则可以轻松使用 MouseEvent 将光标移动到按钮上并单击它。 此示例包含一个即插即用的模块,只需提供窗口句柄即可为您完成脏工作:
http://vb.mvps.org/samples/MouseEvent
否则,最直接的方法可能是按顺序发送
WM_LBUTTONDOWN
和WM_LBUTTONUP
。编辑:如果您“只是想完成它”,请听取 Jim 的建议并尝试 Gary Chanson 的 Window Demon 工具。
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
andWM_LBUTTONUP
sequentially.EDIT: If you "just want to get it done" take Jim's advice and try Gary Chanson's Window Demon tool.
看看这个实用程序 Gary Chanson
Karl 的“Window Demon”:我们多么快就忘记了我们的朋友!
Take a look at this utility "Window Demon" by Gary Chanson
Karl: how quickly we forget our pals!
我建议看看 AutoIt。
它非常适合此任务,查找带有特定文本的窗口,然后单击按钮。
作为独立应用程序在系统托盘中运行。
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.