使用SendKeys从VBA代码控制Word 2016

发布于 2025-02-10 11:56:29 字数 809 浏览 3 评论 0原文

问题:在我的环境中(64位Windows 10),我有成千上万的旧字体文档(.doc)必须更新为新的.docx格式。这些文档分布在共享驱动器上的数千个文件夹中。我找到了一些可以自动化此过程的代码,但是它依赖于安全策略不允许的“对象模型”中的方法。

在信任中心,在“文件块设置”下,我有Word 6.0,Word 95,Word 97和Word 2000文档被阻塞。无法更改这些 - 设置由我的组织管理。

也就是说,即使我无法使用VBA打开它们,我也可以手动打开其中一些文档文件。我认为一种真正的老式方法可能会起作用:打开一个空白的单词应用程序,然后使用send-keys打开DOC文件,然后以新的DOCX格式保存。

我可以在vba 中启动Word

Dim objWordApplication as Word.Application
set objWordApplication = CreateObject("Word.Application")
objectWordApplication.Visible = True

:一旦“对象”运行,我该“发送”它以使其“发送”以打开一个名为xyz.doc的文件?也就是说,在以下代码中,什么是“ ABC”?

objwordapplication.sendkeys(“ abcxyz”,true)

fysa,我的环境受到严格控制。调用任何第三方计划,更改安全设置以及其他“非瓦尼拉”行动的解决方案不会飞行。最后,由于某种原因,我的问题对某些人来说似乎是“作业”,所以我向所有人保证,这是一个生产级别的问题,而不是作业。

在此先感谢您的任何帮助。

The problem: In my environment (64-bit Windows 10) I have tens of thousands of old-format Word documents (.doc) that must be updated to the new .docx format. These documents are spread across thousands of folders on a share drive. I have found some code that can automate this process, but it relies on methods in the Word object model that security policies won't allow.

In the Trust Center, under "File Block Settings", I have word 6.0, word 95, word 97 and word 2000 documents blocked. No way to change these -- settings are managed by my organization.

That said, even though I can't open them using VBA, I can manually open some of these doc files. I'm thinking that a really old-school approach might work: Open a blank Word application, then use send-keys to open the doc files and then save in the new docx format.

I can start Word in VBA

Dim objWordApplication as Word.Application
set objWordApplication = CreateObject("Word.Application")
objectWordApplication.Visible = True

My specific questions: Once the Word object is running, what do I "send" to it to get it to open a file named xyz.doc? That is, in the following code, what is "ABC"?

objWordApplication.SendKeys ("ABCxyz", true)

FYSA, my environment is very strictly controlled. Solutions that invoke any third-party programs, changes to security settings, and other "non-vanilla" actions just won't fly. Finally, for some reason my questions seem like "homework" to some people, so I assure everyone that this is a production-level problem, not homework.

Thanks in advance for any assistance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文