gpt4 book ai didi

vba - 如何在 Excel 中打开特定版本的 Word 2007/2010

转载 作者:行者123 更新时间:2023-12-01 19:04:44 25 4
gpt4 key购买 nike

我安装了 Word 2007 和 2010。我需要从 Excel 中打开 Word,但我需要指定需要在 VBA 中打开哪个版本。

我尝试过后期绑定(bind)

Dim wordApp2007 As Object
Dim wordApp2010 As Object

Set wordApp2007 = CreateObject("Word.Application.12")
wordApp2007.Visible = True
Set wordApp2010 = CreateObject("Word.Application.14")
wordApp2010.Visible = True

但都打开 Word 2010

我还尝试过使用早期绑定(bind)

Dim wordApp As Word.Application
Set wordApp2007 = New Word.Application
wordApp2007.Visible = True

并设置对 Word 12.0 对象模型的引用,但这仍然会打开 Word 2010 enter image description here

如果我使用以下方式注册每个版本的 Word

“C:\Program Files\Microsoft Office\Office12\WINWORD.EXE”/regserver

“C:\Program Files\Microsoft Office\Office14\WINWORD.EXE”/regserver

然后注册的版本可以打开,但是我无法打开未注册的版本。

谁能帮我演示如何使用 VBA 在 Excel 中打开特定版本的 Word?

谢谢

编辑:示例代码....

Option Explicit

Dim wordApp2007 As Word.Application

Sub Word_InfoEarly()
'early binding
Set wordApp2007 = New Word.Application
wordApp2007.Visible = True

'other Stuff
Stop

wordApp2007.Quit
Set wordApp2007 = Nothing

End Sub


Sub Word_InfoLate()
Dim wordApp2007 As Object
Dim wordApp2010 As Object

Set wordApp2007 = CreateObject("Word.Application.12")
wordApp2007.Visible = True
Set wordApp2010 = CreateObject("Word.Application.14")
wordApp2010.Visible = True

'other Stuff
Stop

wordApp2007.Quit
Set wordApp2007 = Nothing
wordApp2010.Quit
Set wordApp2010 = Nothing

End Sub

最佳答案

这是一个解决方法:

TaskID = Shell("C:\Program Files\Microsoft Office\Office12\WINWORD.EXE",vbHide) '2007
'TaskID = Shell("C:\Program Files\Microsoft Office\Office14\WINWORD.EXE",vbHide) '2010
GetObject(,"Word.Application")

您还需要测试旧版本的 word 是否已打开,或者使用除基本 GetObject 以外的其他方法来激活窗口,否则无法保证它将获得正确的版本。

另一种方法是在 Shell 命令中传递文档名称,然后可以使用文档名称调用 GetObject

关于vba - 如何在 Excel 中打开特定版本的 Word 2007/2010,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12073152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com