File does not exist

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a macro that opens a workbook off of my server.
I am wanting to be able to display a dialog box that says that the file does
not exist and then goto to the end of the macro. As is now I get a runtime
error '1004' and you have to end the macro or debug it. I don't want the user
to see this error message.

Here is the code that opens the workbook:
Set destWB = Workbooks.Open("X:\Projects\Group 17 (McLendon)\Group 17
Dayrates\" & wName)
 
Set destWB = Nothing 'jsut to be sure
On ERrror Resume Next
Set destWB = Workbooks.Open("X:\Projects\Group 17 (McLendon)\Group 17
Dayrates\" & wName)
On Error Goto 0
If destWB Is Nothing Then
Msgbox "File does not exist
Exit SUb
End IF

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
sStr = "X:\Projects\Group 17 (McLendon)\Group 17 Dayrates\"
if Dir(sStr & wName) = "" then
msgbox wName & " doesn't exist in " & sStr
exit sub
End if
Set destWB = Workbooks.Open & wName)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top