如何在 Excel 中打开特定版本的 Word 2007/2010 [英] How to open specific version of Word 2007/2010 in Excel

查看:17
本文介绍了如何在 Excel 中打开特定版本的 Word 2007/2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have both Word 2007 and 2010 installed. I need to open Word from within Excel but I need to specify which version I need to open within VBA.

我试过后期绑定

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

but both open Word 2010

我也尝试过使用早期绑定

I've also tried early binding by using

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

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

and setting references to the Word 12.0 object model but this still opens Word 2010

如果我注册每个版本的 Word 使用

If I register each version of Word using

"C:Program FilesMicrosoft OfficeOffice12WINWORD.EXE"/regserver

"C:Program FilesMicrosoft OfficeOffice14WINWORD.EXE"/regserver

然后注册的版本打开但是我无法打开非注册的.

then the version registered opens but then I can't open open the non-registered.

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

Can anyone help and show me how to open a specific version of Word within Excel using VBA?

谢谢

示例代码....

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 FilesMicrosoft OfficeOffice12WINWORD.EXE",vbHide) '2007
'TaskID = Shell("C:Program FilesMicrosoft OfficeOffice14WINWORD.EXE",vbHide) '2010
GetObject(,"Word.Application")

您还需要测试是否打开了以前版本的 word,或者使用基本 GetObject 以外的其他东西来激活窗口,否则无法保证它会获得正确的版本.

You would also need to test if a previous version of word is open, or use something other than a basic GetObject to activate the window, else there's no guarantees that it will get the right version.

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

The other way would be to pass the document name in the Shell command, and then GetObject could be called with the document name

这篇关于如何在 Excel 中打开特定版本的 Word 2007/2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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