2

My Excel spreadsheet has a module (called MyModule) that requires a Reference to be added in order to work. If that Reference is not loaded, I will get this error upon opening the workbook:

Compile error in hidden module: MyModule

So I tried to add the following to Workbook_Open() in ThisWorkbook, such that the Reference will be added upon workbook open:

ActiveWorkbook.Application.VBE.ActiveVBProject.References.AddFromFile pathToMyReference

However, I am still getting the same compile error message. Is there a way to truly add the Reference before the spreadsheet is open?

Community
  • 1
  • 1
Gearbox
  • 336
  • 3
  • 15
  • 1
    You can resolve the binding problem by using "late binding" – xmojmr Nov 03 '17 at 09:30
  • I am aware of "late binding", but is there any other way out? – Gearbox Nov 03 '17 at 09:37
  • [Doesn't look like it](https://stackoverflow.com/a/9221566/4604845), if you disregard setting the reference in advance. – Vegard Nov 03 '17 at 14:12
  • I'm not sure how well this would work, but you could try setting the reference like you're doing now and then [import the actual code at compile time](https://stackoverflow.com/a/1402312/4604845). – Vegard Nov 03 '17 at 14:19

0 Answers0