Closing Word Document

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to close a Word document and tried this code:


Set wordApp = GetObject(, "Word.Application")
Set WordDoc = wordApp.Documents.Open(file_name)
With wordApp

.Documents.Close

End With

How can I check wether the document is open? And how can I close only
the document, not all open word documents?
 
jokobe wrote in message
I want to close a Word document and tried this code:


Set wordApp = GetObject(, "Word.Application")
Set WordDoc = wordApp.Documents.Open(file_name)
With wordApp

.Documents.Close

End With

How can I check wether the document is open? And how can I close only
the document, not all open word documents?

In stead of your with block, try

WordDoc.Close

To check whether a document (file) is open, you could probably loop the
documents collection.

for each oDoc in wordApp.Documents
if oDoc.Name = <name of document> then
' document is open
exit for
end if
next oDoc
 
Back
Top