Shared data (data exchange) between instances of Add-Ins

U

upxtechie

Hello,
I am working on a COM add-in for Word, Excel and PPT and have managed to
share data between the instances of the add-in. The data is stored in global
variables in a module. Just as an example: The add-in is running
simultaneously in Word and Excel. Word is writing some data to the global
variable, and Excel can read that data.

The concept I have used in that add-in project might deviate from what
Microsoft might have intended for COM Add-Ins. I have used 2 (or more)
designer classes in one project, and additionally used "Implements
IDEExtensibility". *** So I wonder if any of you has experience with such a
project design, especially in terms of stability and side effects. *** Any
comments are welcome.

Regards,
Joerg

-------------------------
To demonstrate this concept I have added the details of a sample project to
this post.

General details about the sample project:
I have used VB6 (SP6) with Office Developer 2000 installed on Win2000 SP3
Project links (besides the default ones): "Microsoft Add-In Designer",
"Microsoft Office 9.0 Object library"
The project type is "ActiveX-DLL", start-object="(none)", Threading
model="Apartment Threading"

To the project I have added a module which defines global variables, like:
Option Explicit
Global g_dataExcel As String
Global g_dataWord As String

I use one form named "frmTest" which shows the contents of the global
variables g_dataExcel and g_dataWord


For each application (Word, Excel, ...) I have added one designer class. For
each designer the property "public" is set to "true". Here is the code for
the Word designer:

Option Explicit
Implements IDTExtensibility2

Dim oAppl As Object
Dim WithEvents MyButton As Office.CommandBarButton

Private Sub AddinInstance_Initialize()
Debug.Print "Word - AddinInstance_Initialize"
End Sub

Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object,
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As
Object, custom() As Variant)
Debug.Print "Word - IDTExtensibility2_OnConnection"

Set oAppl = Application

Set MyButton = oAppl.CommandBars("Standard").Controls.Add(1)
With MyButton
.Caption = "My Custom Button"
.Style = msoButtonCaption
.Tag = "My Custom Button"
.OnAction = "!<" & AddInInst.ProgId & ">"
.Visible = True
End With
End Sub

Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)
Debug.Print "Word - IDTExtensibility2_OnAddInsUpdate"
End Sub

Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
Debug.Print "Word - IDTExtensibility2_OnStartupComplete"
g_dataWord = "Word is active"
End Sub

Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
Debug.Print "Word - IDTExtensibility2_OnBeginShutdown"
g_dataWord = "Word was closed down"
End Sub

Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode As
AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
Debug.Print "Word - IDTExtensibility2_OnDisconnection"
On Error Resume Next
MyButton.Delete
Set MyButton = Nothing
Set oAppl = Nothing
End Sub

Private Sub AddinInstance_Terminate()
Debug.Print "Word - AddinInstance_Terminate"
End Sub

Private Sub MyButton_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
Dim oForm As New frmTest
frmTest.Show
End Sub

The code for the Excel designer class is much the same. Only that the data
is written to the variable g_dataExcel. And the debug.print statements are
adopted.
 
P

Peter Huang [MSFT]

Hi Joerg,

Thank your very much for build the Shared Data Sample and send to me.
So far I am researching the issue, I will get back here and give you a
reply ASAP.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top