The File Cannot Be Accessed

I’m trying to run this code:

Set wbStan = Workbooks.Add(gsTemplateFldr & gsSTANFLDR & gsSTAN)

and gsSTAN is a global constant set to ‘Standards.xls’. I forgot to create the folder gsTANDFLDR and, of course, the file is not in there either. I get this error message:

excel error message

The third bullet point is what strikes me as strange. Why is the file name in there? You may have noticed that it’s not a typical message box. The error is run through a error handler, but the message is unchanged.

Posted in Uncategorized

6 thoughts on “The File Cannot Be Accessed

  1. I noticed the same last week when testing whether Unicode characters worked in filenames. I thought it was odd too, but the thing that stood out the most was the last line. I’ve always used a MAX_PATH constant of 260. Why does the error message state 218?

  2. I’d guess the 218 characters have something to do with mapped drive to UNC paths. Like X: mapped to


    That is, I’m guessing that Excel and maybe other Office programs either store UNC pathnames or insist on making provision for them.

  3. I was getting this on OSX Excel (10.1.5 on MacOSX 10.4.10 Intel), so I tried opening Excel itself (no file), and *still* got the error. This leads me to think that it’s something about a template file somewhere? Any ideas where? I got rid of the original ‘MS Office ACL [English]’, ‘Excel Settings (10)’, and ‘Microsoft Office Settings (10)’ files, and the problem still occurs (the second and third files are recreated, but not the ‘ACL’ file). I then tried renaming the ~/Library/Preferences/Microsoft folder (which was recreated), and the problem *still* happened.

    Any ideas short of a full reinstall?

    j(witte)swi(NO SPAM)tte@blooming(trees)ton.(dot)in(diana).us

    (This is a ‘hairy RFC 2822 Address’..)

  4. I managed to find the cause, at least to my problem: I moved the ‘Macro.add’ alias file (found in [Office X directory]/Office/Startup/Excel), and the problem went away. The Macro.add file is the only one there in the Excel directory, and the original file doesn’t seem to exist, so I just removed the entire Excel directory, and I don’t get the error anymore.

    Maybe Excel tries to open the Macro.add file, and reports that it can’t be accessed when the alias doesn’t resolve? A better solution IMO would be to check to see if the alias resolves first – if it doesn’t, alert the user to the SPECIFIC cause of the error (instead of the generic ‘this file canot be accessed’ – “Which file!? I’m not trying to open a file?”), and then either delete the nonfunctional alias file, or recreate whatever the Macro.add file is, and where-ever it originally is. But, this is MS we’re talking about – user-friendlyness especially in border cases like this (this must not happen all that often) do not exactly seem to be a concern.

  5. I had the exact same error message except of course the name of the file showed in the message was different. I tried to find the macro.add file but couldn’t locate in the folder. Later, I found out that in my case, it was a bad link in the icon panel. I use macro quite often, so I pulled an icon out to the panel so I can just click on it. It has been working without any problem. But the error message started to show up. However, I can still access the macro through the drop down manu. I guess I can just recreate an icon for the macro later.

  6. Try ” Long Path Tool ” useful in situations where you see these error messages: Cannot read from source file or disk, there has been a sharing violation, cannot delete file or folder, the file name you specified is not valid or too long, the source or destination file may be in use and many other file managing errors.

Posting code? Use <pre> tags for VBA and <code> tags for inline.

Leave a Reply

Your email address will not be published.