如何将点击或键从 VB6 应用程序发送到 Excel 对话框? [英] How can I send clicks or keys from a VB6 app to an Excel dialog box?

查看:18
本文介绍了如何将点击或键从 VB6 应用程序发送到 Excel 对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的雇主从 Conveter Technology 购买了第三方工具 OfficeConverter,它可以自动将 Office 2003 格式的文件转换/修复为 Office 2007 格式.此工具还高度自动化了 Office 2003 和 2007 格式之间宏/VBA 代码要求的转换/更改.

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.

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

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.

我认为在 VB6 中创建一个小的观看应用程序(嘿,我老了,我的技能也是如此)可以坐在同一台 PC 上观看这些对话框,并根据具体消息,单击相应的按钮通过 SendMessage API 调用.

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.

问题是我无法让 SendMessage 为我实际按下按钮,我尝试将返回键值 (vbKeyReturn) 甚至空格键 (vbKeySpace) 发送给它,但该操作从未产生结果在对话框中像它应该的那样关闭.我可以将焦点切换到启用对话框上的任何按钮之间的选项卡,但仅此而已.

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.

我曾尝试使用 SendKeys,但在我遇到的当前文档中,它的可靠性要低得多,并且强烈建议不要这样做.

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

有什么建议吗?:)

推荐答案

如果您有按钮的 hWnd,并且机器无人看管,您可以轻松地使用 MouseEvent 将光标移动到按钮上并单击它.此示例包含一个插入式就绪模块,该模块将为您完成繁琐的工作,仅提供窗口句柄:

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

否则,最直接的方法可能就是按顺序发送WM_LBUTTONDOWNWM_LBUTTONUP.

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

如果您只想完成它",请采纳 Jim 的建议并尝试 Gary Chanson 的 Window Demon 工具.

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

这篇关于如何将点击或键从 VB6 应用程序发送到 Excel 对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆