Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a C# VSTO / VBA hybrid project.

When a user opens a valid Excel workbook using my VSTO app, a VBA property is set from C# as such:

worksheet.GetType().InvokeMember("AddInIsLoaded",
                                             System.Reflection.BindingFlags.Default |
                                             System.Reflection.BindingFlags.SetProperty, null, worksheet, new object[]{true});

This works as expected. There are a then a few other processes within the VBA, and at each stage I check if the property is still set using

MsgBox AddInIsLoaded

Each time I receive the affirmative message.

When the user selects 'SaveAs', if the AddInIsLoaded property is true then I want control of the save functionality to be handled by my VSTO app. The issue is that I have an event handler as such

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

If SheetExists("Protocol") = True Then
    If AddInIsLoaded = True Then
    Exit Sub
    End If
End If

End Sub

Within this event handler the AddInIsLoaded property always shows as false, even though right up to when I press SaveAs, the property shows as true.

Does anybody know any reason why this would be the case?

Thanks.

share|improve this question
    
Where is AddInIsLoaded defined in your VBA code? Is it possibly defined in two different places? (most likely to cause this behavior would be as Public in a module and as Private in ThisWorkbook) –  RBarryYoung Jun 27 '13 at 18:07
    
@RBarryYoung It's only defined in the one place?? –  Darren Young Jun 27 '13 at 18:36
1  
What one place is that? If it's a module, then modify all of your references to make the module name explicit (i.e., Module1.AddInIsLoaded) and re-test. Also, you may want to try adding Option Explicit, at least to ThisWorkbook. –  RBarryYoung Jun 27 '13 at 18:41
    
@RBarryYoung Thanks. Will give your suggestions a try when I'm back at work tomorrow. Will post an update then. :) –  Darren Young Jun 27 '13 at 18:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.