How to write On Error code for finding a file?

lookingforK

Registered User.
Local time
Today, 09:49
Joined
Aug 29, 2012
Messages
48
How to write On Error code for opening a file?

Hi,

I want to use On Error code for opening a file.

Something like:
Code:
On Error GoTo findtemplate_error
 
Set wkbDest = xl.Workbooks.Open(strReportPath & "\Template.xlsx")
 
findtemplate_error:
If [COLOR=red]{find [Template.xlsx]}[/COLOR] Then {GoTo ...[I]continue[/I]}
Else 
MsgBox "[Template.xlsx] cannot be found under this folder. Please try a different path. "
Exit Sub
End If

How to write the code for the part {find [Template.xlsx]}? :banghead:


Thank you in advance.
 
Last edited:
You mean when the file doesn't exist in that path? Use proper error handling:

http://www.baldyweb.com/ErrorTrap.htm

Figure out what error number is returned for that error (running it without error handling should display that), and add it to the error handler.
 
Thank you pbaldy.

Is the error number the returned Run-time error #, e.g. '1004'?
 
Yes, in the error trap you'd have

Case 1004
 

Users who are viewing this thread

Back
Top Bottom