Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-29-2015, 10:41 AM
newbieX newbieX is offline Cannot find file only when opened directly from Word Windows 7 64bit Cannot find file only when opened directly from Word Office 2007
Novice
Cannot find file only when opened directly from Word
 
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
Reply

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
Cannot find file only when opened directly from Word Import .txt file directly into Outlook email tcurrier52 Outlook 1 12-11-2013 12:08 PM
Cannot find file only when opened directly from Word [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
Cannot find file only when opened directly from Word How to open ppt file directly with slide show when clicked on file. praveen_p PowerPoint 1 05-06-2009 12:42 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:42 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft