views:

544

answers:

1

I have an Excel add-in I am developing that works fine in Windows XP. However, I just got a hold of Windows 7 Professional and now I cannot save this add-in, either manually from the VBA Editor or programmatically using ThisWorkbook.Save.

The error message says "Micrsosoft Office Excel cannot access the file 'C:\Program Files\Microsoft Office\Office 12\LIBRARY[some random 8-character string rather than the name of my add-in]". One of this dialog error's possible explanations is that "The file name or path does not exist". Well, of course it doesn't.

I tried turning off read-only on the add-in file and its directory, as well as "Unblocking" the file (seems to be a new Windows 7 feature) using the Properties dialogs, but to no avail.

Any ideas on what I can do to get this basic Save functionality to work in Windows 7???

+4  A: 

I'm guessing this is the UAC behaviour of Windows that was introduced in Vista, and is still in Windows 7.

Have a look at this Microsoft page for a user perspective, and this MSDN one for an idea of how to program with it in mind.

In summary, you can't write to Program Files without asking for elevation if you have UAC on.

(Edit: couple of extra points raised by the comments) If this is just for development, you can run Excel using right click->'Run as Administrator', which will let you save where you want, or you can save in %AppData%\Microsoft\Addins, which is also a trusted location (see this MSDN article for more details of that).

Ant
I think you're correct about the UAC. I checked out the links, but didn't find anything that helps me around this problem. My add-in file is actually located in a Trusted Location used by Excel, not the Program Files directory. I have to believe that there are other add-ins written in VBA that have encountered this problem...
Ryan
Are you able to save inside the user folder (%appdata%)? If your Trusted Location is not in Program Files, but still in one of the restricted places you'll still have problems. If this is just for development, you can run Excel using right click->'Run as Administrator', which will let you save where you want.
Ant
Ant, you're right on the money. The add-in must be saved to C:\Users\[User Name]\AppData\Roaming\Microsoft\Addins, or you can use a Trusted Location path if logged in under a UAC. Thanks so much for your help.
Ryan
No problem - glad to have helped!
Ant
Ryan, you should give Ant the check mark since he solved this for you. (Ant, you get a +1 from me, in any case -- nice answer.)
Mike Rosenblum
Thanks very much :)
Ant