2008-12-16 22 views
1

當我嘗試以編程方式訪問一個Word對象模型時,出現錯誤,指出沒有文檔處於活動狀態。這似乎是因爲我使用Word自動化將文檔加載爲不可見,並且我必須保持它不可見。無法訪問MSWord ActiveDocument

我該如何編碼開放的宏,使它在這種情況下什麼都不做?

If Not ActiveDocument is Nothing Then

沒有工作。

Private Sub Document_Open() 

    If (ActiveDocument.SaveFormat = wdFormatRTF) Then 
     'Do some stuff 
    End If 

End Sub 

回答

1

而不是使用你的ActiveDocument可以記住您打開(一些原理代碼)的文件:

dim word as new Word.Application 
dim doc as Word.Document 

doc = word.Documents.Open(fileName) 
MsgBox doc.FullName 
0
If Documents.Count > 0 Then