We help IT Professionals succeed at work.

How to check if file exists in Word macro

ksander
ksander asked
on
In a Word macro I ask a user for a path and file name to start a a mail merge.  If the user supplies a bad filespec an ugly message appears.

I would like to check to see if the file exists and if it doesn't ask the user to try again.

Any help will be appreciated.
Comment
Watch Question

Commented:
if the entered file name is held in the variable strEnteredFilename then use this:


If dir(strEnteredFilename) = "" then
  beep
  msgbox "The file does not exist", vbCritical+vbOkOnly, "File Error"
  exit sub
end if

Author

Commented:
That did the trick - thanks

Explore More ContentExplore courses, solutions, and other research materials related to this topic.