从excel打开word [英] Open word from excel
本文介绍了从excel打开word的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法从 Excel 宏 (Office XP) 中打开 Word.如果我使用此代码,它将在 Set wdDoc = wordapp.Documents.Open(polozka.ShortPath)
行停止并且程序冻结.如果我使用 Set wdDoc = GetObject(polozka.ShortPath)
而不是这一行,程序会在此处停止 With wdDoc.Selection
并出现错误:
I can't open Word from Excel macro (Office XP). If I use this code, it will stop on line Set wdDoc = wordapp.Documents.Open(polozka.ShortPath)
and program freezes. If I use Set wdDoc = GetObject(polozka.ShortPath)
instead of this line, program stops here With wdDoc.Selection
with error:
对象不支持此属性"
Dim wordapp As Word.Application
Dim wdDoc As Word.Document
Set fso = CreateObject("Scripting.FileSystemObject")
Set files = fso.GetFolder("C:path").Files
Set wordapp = CreateObject("Word.Application")
For Each polozka In files
Set wdDoc = wordapp.Documents.Open(polozka.ShortPath)
wordapp.Visible = True
With wdDoc.Selection
.HomeKey Unit:=6
.Find.Text = "Název (typ):"
.Find.Wrap = wdFindContinue
...
End With
...
wordapp.Quit
Set wordapp = Nothing
Next
推荐答案
你必须像下面这样声明你的变量as Object
:
You have to declare your variable as Object
like below:
Dim Paragraphe As Object, WordApp As Object, WordDoc As Object
并使用文档:
File= "D:path"
'Word session creation
Set WordApp = CreateObject("Word.Application")
'word will be closed while running
WordApp.Visible = False
'open the .doc file
Set WordDoc = WordApp.Documents.Open(File)
并关闭应用程序:
WordDoc.Close
WordApp.Quit
Set WordDoc = Nothing
Set WordApp = Nothing
希望能帮到你.
这篇关于从excel打开word的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文