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.
AddInIsLoaded
defined in your VBA code? Is it possibly defined in two different places? (most likely to cause this behavior would be asPublic
in a module and asPrivate
in ThisWorkbook) – RBarryYoung Jun 27 '13 at 18:07Module1.AddInIsLoaded
) and re-test. Also, you may want to try addingOption Explicit
, at least to ThisWorkbook. – RBarryYoung Jun 27 '13 at 18:41