tags:

views:

126

answers:

2

When I try to programmatically access a word object model, I get an error no document is active. This appears to be because I am loading the document as not visible using Word automation, and I have to keep it invisible.

How would I code the open macro so that it does nothing in this case? "If Not ActiveDocument is Nothing Then" didn't work.

Private Sub Document_Open()

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

End Sub
+1  A: 

Instead of using ActiveDocument you could remember the document that you open (some schematic code):

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

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