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

23,414

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

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

Share:
23,414
Travis Kopp
Author by

Travis Kopp

Super amateur coder - but I'm learning!

Updated on December 29, 2020

Comments

  • Travis Kopp
    Travis Kopp over 3 years

    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")
    
    • Rory
      Rory over 8 years
      You need to remove the reference and late bind your code if you need to support multiple versions.