我無法從Excel宏(office xp)打開Word。如果我使用此代碼,它將停止在行Set wdDoc = wordapp.Documents.Open(polozka.ShortPath)
並且程序凍結。如果我使用Set wdDoc = GetObject(polozka.ShortPath)
而不是這條線,計劃在這裏With wdDoc.Selection
停止與「對象不支持此屬性...」錯誤VBA:從excel打開word
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
謝謝,現在我可以用第一種方式打開文檔,但仍然程序在這裏停止'With wdDoc.Selection' with「Object does not support this property or method」error – koubin 2013-05-09 07:38:37
我找到了解決辦法。將此行改爲'用wdDoc.Selection'改爲'用wordapp.Selection'解決它。但是我仍然不知道,爲什麼我不能使用'wdDoc'對象 – koubin 2013-05-09 15:27:13