I have some code that looks for a file in a given directory and deletes it if it is found. When I open the file by clicking on the file name from the directory, the file is found when macro is executed. When I open it from within word, I get an error message telling me the file is not found.
Why is this happening and how might I alter this code to prevent this?
Code:
Dim myFile As String
Dim myPath As String
myPath = ActiveDocument.Path & "\"
myFile = Dir$(DocPath & "*Stats.pdf")
If MsgBox("Select OK to continue, Cancel to Exit", vbOKCancel) = vbCancel Then Exit Sub
If Len(myFile) > 0 Then
Kill myFile
End If
Thanks in advance