Excel add-in - Why must VBA project be compiled first??

%3CLINGO-SUB%20id%3D%22lingo-sub-2874786%22%20slang%3D%22en-US%22%3EExcel%20add-in%20-%20Why%20must%20VBA%20project%20be%20compiled%20first%3F%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2874786%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20written%20a%20VS%20solution%20that%20contains%3A%3CBR%20%2F%3E1)%20A%20C%23%20project%20for%20an%20Excel%20document-level%20add-in.%20The%20project%20contains%20the%20XLSM%20file.%3C%2FP%3E%3CP%3E2)%20A%20Windows%20Installer%20project%20for%20installing%20the%20add-in%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20XLSM%20file%20(included%20in%20the%20installation)%20contains%20some%20VBA%20macros%20written%20to%20interface%20with%20the%20C%23%20side.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20problem%20arises%20once%20I%20install%20the%20add-in%2C%20open%20the%20XLSM%20file%2C%20and%20run%20a%20macro.%20The%20standard%20VBA%20error%20%22Can't%20find%20project%20or%20library%22%20pops-up.%20If%20I%20then%20go%20into%20the%20developer%20Visual%20Basic%20editor%20and%20compile%20the%20project%20(Debug%20%26gt%3B%20Compile%20VBAProject)%20no%20errors%20are%20reported.%20However%2C%20if%20I%20rerun%20the%20macro%20it%20works%20just%20fine.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20is%20going%20on%20here%3F%20Why%20does%20compiling%20the%20VBA%20fix%20enable%20the%20macros%20to%20work%20even%20though%20there%20were%20no%20errors%20to%20be%20found%3F%20And%20how%20can%20I%20include%20an%20XLSM%20in%20my%20Windows%20Installer%20project%20that%20works%20out%20of%20the%20box%3F%20Please%20help!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2874786%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
New Contributor

I have written a VS solution that contains:
1) A C# project for an Excel document-level add-in. The project contains the XLSM file.

2) A Windows Installer project for installing the add-in

 

The XLSM file (included in the installation) contains some VBA macros written to interface with the C# side.

 

My problem arises once I install the add-in, open the XLSM file, and run a macro. The standard VBA error "Can't find project or library" pops-up. If I then go into the developer Visual Basic editor and compile the project (Debug > Compile VBAProject) no errors are reported. However, if I rerun the macro it works just fine.

 

What is going on here? Why does compiling the VBA fix enable the macros to work even though there were no errors to be found? And how can I include an XLSM in my Windows Installer project that works out of the box? Please help!

 

0 Replies