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

问题描述

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



我已经尝试延迟绑定

$ b $对于

设置wordApp2007 = CreateObject(Word.Application.12)
wordApp2007.Visible = True
设置wordApp2010 = CreateObject(Word.Application.14)
wordApp2010.Visible = True

但都打开Word 2010



我也尝试过早期绑定使用

  Dim wordApp作为Word.Application 
设置wordApp2007 =新的Word.Application
wordApp2007.Visible = True

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



如果我使用

$ b注册每个版本的Word
$ b

C:\Program Files\Microsoft Offi c \程序文件Office \Office14\WINWORD.EXE/ regserver



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



任何人都可以帮助并告诉我如何使用VBA在Excel中打开特定版本的Word?



谢谢



编辑:示例代码....

 选项显式

Dim wordApp2007作为Word.Application

Sub Word_InfoEarly()
'早期绑定
设置wordApp2007 =新的Word.Application
wordApp2007.Visible = True

'其他资料
停止

wordApp2007.Quit
设置wordApp2007 =没有

结束子


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

设置wordApp2007 = CreateObject(Word.Application。 12)
wordApp2007.Visible = True
设置wordApp2010 = CreateObject(Word.Application.14)
wordApp2010.Visible = True

'其他东西
停止

wordApp2007.Quit
设置wordApp2007 =没有
wordApp2010.Quit
设置wordApp2010 =没有

End Sub


解决方案

这是一个工作:

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

您还需要测试以前版本的单词是否打开,或者使用除基本 GetObject 之外的其他东西来激活窗口,否则不保证它会获得正确的版本。



另一种方法是将文件名称传递给 Shell 命令,然后 GetObject 可以使用文档名称


调用

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.

I've tried late binding

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

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

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

If I register each version of Word using

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

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

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

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

Thank you

Edit: Example code....

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
解决方案

This is a work around:

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")

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.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 22:13