0
votes

I am trying to suppress the following message box from occurring or have it go to the error message line if it does occur. " Sorry we couldn't find xxx is it possible if it was moved..."

Normally I would check if the dir(Folderpath & Filename) <> 0. However, these files are on a sharepoint server. So regardless of whether the files exist or not I get a runtime 52 error: "Error 52: Bad filename or number." This error occurs when launching an FRx install that points to a network SysData directory."

Where I am confused is the below snippet works if the file exist.

Set stateWb = Workbooks.Open(folderPath & fileName)

However, if it does not exist I receive the " Sorry we couldn't find xxx is it possible if it was moved...". The goal is that if the workbooks.open fails, go to error message and print the following msgBox " State Data not available".

Currently it does both it gives the message " Sorry we couldn't find xxx is it possible if it was moved..." and also produces the msgbox " State Data not available".

Thoughts?

1
Is your used code top secret? Please, edit your question and post the code you use. What kind o path do you use? Firstly, I would suggest you to replace dir(Folderpath & Filename) <> 0 with dir(Folderpath & Filename) <> "". Dir returns a string. And be sure that between Folderpath and Filename it is a back slash character.FaneDuru

1 Answers

0
votes

You can avoid the "Sorry we couldn't find xxx is it possible if it was moved..." error by using:

On Error GoTo error_Check

...code...

Set stateWb = Workbooks.Open(folderPath & fileName)

...code...

error_Check:
MsgBox "State Data not available"

However, in this case any error in the procedure will go here so...