![]() |
|
#1
|
|||
|
|||
|
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
|
|
| Tags |
| vba word, word 2010 |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Word Changes File Name When Opened | canonm@pacbell.net | Word | 1 | 06-11-2014 10:04 PM |
Import .txt file directly into Outlook email
|
tcurrier52 | Outlook | 1 | 12-11-2013 12:08 PM |
[Word 2007] How to hyperlink directly another word file chapter/paragraph/bookmark?
|
LeeFX | Word | 4 | 05-05-2011 05:53 PM |
| Programmatically get File Path for currently opened WORD document | franferns | Word | 1 | 11-26-2009 12:36 PM |
How to open ppt file directly with slide show when clicked on file.
|
praveen_p | PowerPoint | 1 | 05-06-2009 12:42 PM |