View Single Post
 
Old 07-29-2015, 10:41 AM
newbieX newbieX is offline Windows 7 64bit Office 2007
Novice
 
Join Date: Mar 2014
Posts: 6
newbieX is on a distinguished road
Default Cannot find file only when opened directly from Word

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
Reply With Quote