Link to home
Create AccountLog in
Avatar of HugoHiasl
HugoHiasl

asked on

Add-In Express Exception when accessing Excel VBProject property

Hi..

I created an Add-In for Excel with Add-In Express. It is in the Workbook_Open event and works fine with nearly all workbooks.

But I have one workbook with macros in it that pops up with a security warning when I open it because it is not a trusted location. Normally I click "Enable Macros".

When I do this after installing the Add-In it throws an exception in the first of the following rows.

                bool test1 = (ExcelApp.ActiveWorkbook.VBProject != null);
                bool test2 = (ExcelApp.ActiveWorkbook.VBProject.Protection == Microsoft.Vbe.Interop.vbext_ProjectProtection.vbext_pp_none);
                bool test3 = (ExcelApp.ActiveWorkbook.VBProject.VBComponents != null);


                // check if there are components to keep safe from exceptions
                if ((ExcelApp.ActiveWorkbook.VBProject != null) && (ExcelApp.ActiveWorkbook.VBProject.Protection == Microsoft.Vbe.Interop.vbext_ProjectProtection.vbext_pp_none) && (ExcelApp.ActiveWorkbook.VBProject.VBComponents != null)) {

Open in new window


the three bool variables were only introduced to break down the error because it first appeared in the if-condition which consists of three conditions.

The error is:
"Exception from HRESULT: 0x800A03EC"

Does anyone know where the problem is?

Thanks in advance
Oliver
ASKER CERTIFIED SOLUTION
Avatar of Mihai Stancescu
Mihai Stancescu
Flag of Romania image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of HugoHiasl
HugoHiasl

ASKER

Did not solve it but pointed me to a right direction...