Reputation: 159
Here's my code:
If Not (word.ActiveDocument Is Nothing) Then
word.ActiveDocument.Close SaveChanges:=wdSaveChanges
End If
I get an error if there is no active document. How can I prevent this?
Upvotes: 0
Views: 982
Reputation: 32682
You can check if there are open documents in the following way:
If word.Documents.Count Then '0 is falsy, all other values are truthy
word.ActiveDocument.Close SaveChanges:=wdSaveChanges
End If
Upvotes: 2