Adam Tegen
Adam Tegen

Reputation: 25905

Trouble accessing MSWord ActiveDocument

When I try to programmatically access a Word object model, I get an error saying 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

Upvotes: 1

Views: 528

Answers (2)

Foole
Foole

Reputation: 4850

If Documents.Count > 0 Then

Upvotes: 0

Dirk Vollmar
Dirk Vollmar

Reputation: 176259

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

Upvotes: 1

Related Questions