vba Office 2016 -> 2013“编译错误,找不到项目或库”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32764578/
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
Office 2016 -> 2013 "compile error, can't find project or library"
提问by Travis Kopp
I just upgraded to Office 2016, which most of my users haven't done, and I'm getting a new error when users try to run my scripts.
我刚刚升级到 Office 2016,我的大多数用户还没有升级,当用户尝试运行我的脚本时,我收到了一个新错误。
"Compile Error, can't find project or library"
“编译错误,找不到项目或库”
I looked in the references and it looks like it's trying to reference the "Microsoft Word 16.0 Object Library" and it's missing on machines running Office 2013. I don't see the option to change my reference to a 2013 version, and I don't know how to give my users access to the 2016 reference without upgrading everyone (not an option right now).
我查看了参考资料,它看起来像是在尝试引用“Microsoft Word 16.0 对象库”,但在运行 Office 2013 的计算机上却没有。我没有看到将我的引用更改为 2013 版本的选项,我也没有看到我不知道如何在不升级每个人的情况下让我的用户访问 2016 年参考(现在不是一个选项)。
This error is coming up on the first executable line of code
此错误出现在第一个可执行代码行上
Set app = Range("A2")
回答by Clint Street
You need to include the Excel 15.0 Object Library in order to use Excel.Range("A2") like that or use late binding as shown below:
您需要包含 Excel 15.0 对象库才能像这样使用 Excel.Range("A2") 或使用后期绑定,如下所示:
Dim excelApp As object, r as object
Set excelApp = CreateObject("Excel.Application")
Set r = excelApp.Range("A2")
回答by GSerg
Office documents where the VBA project references Office apps will work on later Office versions too. When you open them on the later version, they will appear to reference that later version.
VBA 项目引用 Office 应用程序的 Office 文档也适用于更高版本的 Office。当您在更高版本上打开它们时,它们将显示为引用该更高版本。
However if you save such file with a later Office version and then open it with the original Office version, you will have MISSING:references to any Office apps other that the one to which the file belongs.
That is, if you have an Excel file that references Excel and Word, resave it under Office 2016 and then open in Office 2013, the reference to Excel will be fine, but the reference to Word will be MISSING:.
但是,如果您使用更高版本的 Office 版本保存此类文件,然后使用原始 Office 版本打开它,则您将MISSING:引用该文件所属的任何 Office 应用程序以外的任何 Office 应用程序。
也就是说,如果你有一个引用 Excel 和 Word 的 Excel 文件,在 Office 2016 下重新保存,然后在 Office 2013 中打开,对 Excel 的引用就可以了,但对 Word 的引用将是MISSING:.
To avoid this, either always save the file under the earliest Office version that you support, or completely remove the references to other Office apps and use late bindingto call them.
为避免这种情况,请始终将文件保存在您支持的最早 Office 版本下,或者完全删除对其他 Office 应用程序的引用并使用后期绑定来调用它们。

