This code is in a word macro template in the word start up menu. It can be executed from any word document.
Dim myFile As String
Dim myPath As String
myPath = ActiveDocument.Path & "\"
myFile = Dir$(myPath & "*Invoice.pdf")
If Len(myFile) > 0 Then
Debug.Print Len(myFile)
Debug.Print myFile
Kill myFile
End If
When I run this code I get an error message "File not found" if I have another MS Word file open when I opened this instance of a word document and executed the macro.
Length is > 0 Filename (Greenbriar - Invoice.pdf) is correct and present. (there is always only one pdf with "Invoice" in the filename in any given folder)
I do not get this error message if no other word document is open.
How can I modify the code to run even if another Word document is open?
Thanks in advance.
ActiveDocument
call I assume... – Chrismas007