vba 在 Windows 7 中保存 Excel 加载项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2071630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Saving Excel Add-In in Windows 7
提问by OfficeAddinDev
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
.
我有一个正在开发的 Excel 插件,它在 Windows XP 中运行良好。但是,我刚刚掌握了 Windows 7 Professional,现在我无法保存此加载项,无论是从 VBA 编辑器手动保存还是使用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]".
“Microsoft Office Excel 无法访问文件‘C:\Program Files\Microsoft Office\Office 12\LIBRARY[一些随机的 8 字符字符串,而不是我的加载项名称]”。
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.
我尝试关闭加载项文件及其目录的只读,以及使用“属性”对话框“解除阻止”文件(似乎是 Windows 7 的新功能),但无济于事。
How do I get this basic save functionality to work in Windows 7?
如何让这个基本的保存功能在 Windows 7 中工作?
回答by Ant
I'm guessing this is the UAC behaviour of Windows that was introduced in Vista, and is still in Windows 7.
我猜这是在 Vista 中引入的 Windows 的 UAC 行为,并且仍在 Windows 7 中。
Have a look at this Microsoft pagefor a user perspective, and this MSDN onefor an idea of how to program with it in mind.
从用户的角度看这个 Microsoft 页面,以及这个 MSDN页面,了解如何使用它进行编程。
In summary, you can't write to Program Files without asking for elevation if you have UAC on.
总之,如果您打开了 UAC,则无法在不要求提升的情况下写入程序文件。
(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 articlefor more details of that).
(编辑:评论提出了一些额外的观点)如果这只是为了开发,您可以使用右键单击->'以管理员身份运行'运行 Excel,这将让您保存所需的位置,或者您可以保存在 %AppData %\Microsoft\Addins,这也是一个受信任的位置(有关更多详细信息,请参阅此 MSDN 文章)。
回答by pierre
The problem seems to be related with the directory you try to save the file. Thus, one possible solution is to use an alternative directory. In order to do that, - First, remove any previous reference. - Next, you need to create a trusted folder location (File/Options/Trust Center/Trust Center Settings/Trusted Locations/Add new location). - Copy the addins to this newly created trusted folder. - Finally, File/Options/Add-ins/Manage Excel Add-ins, add the addin.
问题似乎与您尝试保存文件的目录有关。因此,一种可能的解决方案是使用替代目录。为了做到这一点, - 首先,删除任何以前的引用。- 接下来,您需要创建一个受信任的文件夹位置(文件/选项/信任中心/信任中心设置/受信任位置/添加新位置)。- 将插件复制到这个新创建的受信任文件夹。- 最后,文件/选项/加载项/管理 Excel 加载项,添加加载项。