I am using the following code (simplified version):
Option Explicit
Sub CloseDocs()
Do
Dim wrdApp As Object
Dim wrdD As Object
Set wrdApp = GetObject(, "Word.Application")
wrdApp.Visible = True
If wrdApp Is Nothing Then
MsgBox "No instances of Word found"
Exit Sub
End If
wrdD.Close SaveChanges = False
Set wrdApp = Nothing
Set wrdD = Nothing
MsgBox ""
Loop
End Sub
I am using Office 2010, so can't use wrdApp.Documents.Count in the loop due to the bug in Word 2010, hence the code above
The code was running fine in 2003. The problem I have is that during the loop, intermitently, a document closes and leaves behind a 'blank' instance of Word with no document, and this causes the code to break before having closed all the documents.