Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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")
like image 903
Travis Kopp Avatar asked Sep 24 '15 14:09

Travis Kopp


People also ask

Can't find project or library error Excel 2016?

Press the ALT and F11 keys to open the Visual Basic Editor in a new window. Click on the Tools menu item, and click on References. Step 3. The dialogue box will display “missing object library or type” as shown below.

Why do I get can't find project or library?

This error is usually caused by the user's MS Access or MS Excel program. The reason is that the program has a reference to an object or type of library which is missing and hence not found by the program. Accordingly, the program cannot use VB or Micro based functions or buttons.

What does can't find project or library mean in Excel?

Every program has a reference to an object or the type of library. If the program can not identify the reference or type of library, hence, the program can not use in VBA Macros, then it shows an error named “can't find project or library”.

How do I fix compile errors in VBA?

I have resolved same error by following these 4 steps : Open Excel file which is having issue, press Alt + F11 go into its Visual Basic Editor. From the Tools menu select References ( Note, if references option is disabled in tools menu try closing and reopening file and enable Macro before proceeding next steps)


2 Answers

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")
like image 104
Clint Street Avatar answered Sep 18 '22 01:09

Clint Street


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.

like image 32
GSerg Avatar answered Sep 19 '22 01:09

GSerg