Office 2016 -> 2013 “compile error, can't find project or library”

风流意气都作罢 提交于 2019-12-18 04:59:14

问题


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.

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

This error is coming up on the first executable line of code

Set app = Range("A2")

回答1:


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:

  Dim excelApp As object, r as object
  Set excelApp = CreateObject("Excel.Application")
  Set r = excelApp.Range("A2")



回答2:


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.

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

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 binding to call them.



来源:https://stackoverflow.com/questions/32764578/office-2016-2013-compile-error-cant-find-project-or-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!