Problem accessing MSWord ActiveDocument

When I try to programmatically access the Word object model, I get an error when no document is active. This is because I load the document as invisible using Word automation and I have to keep it invisible.

How do I code an open macro so that it doesn't do anything in this case?

If Not ActiveDocument is Nothing Then

does not work.

Private Sub Document_Open()

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

End Sub

      

+1


source to share


2 answers


Instead of using ActiveDocument, you can think of the document being opened (some schematic code):



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

doc = word.Documents.Open(fileName)
MsgBox doc.FullName

      

+1


source


If Documents.Count > 0 Then

      



0


source







All Articles