I am trying to figure out the VBA syntax to open and close Word documents. This is what I have so far:
Dim wordApp as Word.Application
Set wordApp = GetObject(,"Word.Application"
'If an instance of Word is open, then check to see if FilePath is on of the open documents
With wordApp
For Each Document In wordApp.Documents
If (Document.FullName = FilePath) Then
found=true
Document.Close
End If
Next Document
End With
Essentially, I want to determine if an instance of Word is open, then scroll through the documents, see if the one I'm looking for (FilePath) is open. If it is, then close it.
This document is set to read only, so I'm trying to figure out how to close without saving it.
Also, I get errors saying 'ActiveX component can't create object' when I try to run the code without Word being open. Is there anyway to get around this? Any help would be greatly appreciated!!! Thanks!!!!!
Dim wordApp as Word.Application
Set wordApp = GetObject(,"Word.Application"
'If an instance of Word is open, then check to see if FilePath is on of the open documents
With wordApp
For Each Document In wordApp.Documents
If (Document.FullName = FilePath) Then
found=true
Document.Close
End If
Next Document
End With
Essentially, I want to determine if an instance of Word is open, then scroll through the documents, see if the one I'm looking for (FilePath) is open. If it is, then close it.
This document is set to read only, so I'm trying to figure out how to close without saving it.
Also, I get errors saying 'ActiveX component can't create object' when I try to run the code without Word being open. Is there anyway to get around this? Any help would be greatly appreciated!!! Thanks!!!!!