Tornado1981
Board Regular
- Joined
- Apr 1, 2010
- Messages
- 248
Hi,
I'm trying to check whether a specific word document is open or not. If open, then close it and first then reopen again and if not then just open it.
The problem is that I always get a Bad file name 4160 error when it tries to close the document.
Would anyone plz tell me where exactly is the problem in my code.
Thank u in advance.
I'm trying to check whether a specific word document is open or not. If open, then close it and first then reopen again and if not then just open it.
The problem is that I always get a Bad file name 4160 error when it tries to close the document.
Would anyone plz tell me where exactly is the problem in my code.
Thank u in advance.
Code:
Dim wdApp As Object
Dim myDoc As Word.Document
Set wdApp = GetObject(, "Word.Application")
If IsFileOpen(FilePath & "TemporaryLetter.docx") Then
wdApp.Documents(FilePath & "TemporaryLetter.docx").Close
End If
With wdApp
.Visible = True
.WindowState = 2
End With
Set myDoc = wdApp.Documents.Open(FilePath & "TemporaryLetter.docx")