I want to make an ActiveX Control for Word, Excel and Access 2010 with VB 2012 so I started from the sample VB ActiveX Control from MSDN:
VB ActiveX Control (VBActiveX). The control work as expected except for properties persistence which only works in Excel, for Word and Access the properties are persisted only at the creation of the control on the form.
I guess there is a default implementation of the IPersistPropertyBag interface in the CCW since the persistence works in Excel but as it’s not working with Word and Access I am trying to provide my own implementation of the interface in my Control which should override the interface in the CCW.
Here is the code I added the VBActiveX project:
<ComImport, Guid("55272A00-42CB-11CE-8135-00AA004BB851"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
Public Interface IPropertyBag
Sub Write(<[In]> Name As String, <[In]> ByRef Value As Object)
Sub Read(<[In]> Name As String, ByRef Value As Object, ErrorLog As Integer)
End Interface
<ComImport, Guid("0000010C-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
Public Interface IPersist
<PreserveSig>
Sub GetClassID(<[Out]> ByRef ClassID As Guid)
End Interface
<ComImport, Guid("37D84F60-42CB-11CE-8135-00AA004BB851"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
Public Interface IPersistPropertyBag
Inherits IPersist
<PreserveSig>
Shadows Sub GetClassID(<[Out]> ByRef ClassID As Guid)
<PreserveSig>
Sub InitNew()
<PreserveSig>
Sub Load(PropertyBag As IPropertyBag, ErrorLog As Integer)
<PreserveSig>
Sub Save(PropertyBag As IPropertyBag, <[In]> ClearDirty As Boolean, <[In]> SaveAll As Boolean)
End Interface
Private Sub GetClassID(ByRef ClassID As Guid) Implements IPersist.GetClassID, IPersistPropertyBag.GetClassID
Debug.Print("IPersistPropertyBag.GetClassID")
ClassID = Me.GetType().GUID
End Sub
Private Sub IPersistPropertyBag_InitNew() Implements IPersistPropertyBag.InitNew
Debug.Print("IPersistPropertyBag_InitNew")
End Sub
Private Sub IPersistPropertyBag_Load(PropertyBag As IPropertyBag, ErrorLog As Integer) Implements IPersistPropertyBag.Load
Debug.Print("IPersistPropertyBag_Load")
End Sub
Private Sub IPersistPropertyBag_Save(PropertyBag As IPropertyBag, ClearDirty As Boolean, SaveAll As Boolean) Implements IPersistPropertyBag.Save
Debug.Print("IPersistPropertyBag_Save")
End Sub
I only have some Debug Print in my implementation for now to see if it is called by Word or Excel and from what I can see in the Output Window nothing in the interface is called. Does anybody know what I am missing?