简体   繁体   中英

Alternative to Dir() to check whether network file exist if user doesnt have write access

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?

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM