Word Open Events if another addin is installed

Add-in Express™ Support Service
That's what is more important than anything else

Word Open Events if another addin is installed
 
Thomas Bach


Guest


Hi,

our plugin use the DocumentBeforeClose and DocumentOpen Events to set the state of different RibbonBar Buttons. Also, there is a check about opening the same document twice.

It works, but we have a problem, if another add-in like camtasia stdio is installed. It seems that the open event is catched by camtasia.

Did you have some other ideas, how i can do that?

I have two buttons. One for open and one for save. The save button should only be enabled, if one or more documents are opened.



Private Sub adxWordEvents_DocumentBeforeClose(ByVal sender As Object, ByVal e As AddinExpress.MSO.ADXHostBeforeActionEventArgs) Handles adxWordEvents.DocumentBeforeClose
        If WordApp.Documents.Count = 1 Then
            Disable_Save_Button()
        Else
            Enable_Save_Button()
        End If
    End Sub

    Private Sub adxWordEvents_DocumentOpen(ByVal sender As Object, ByVal hostObj As Object) Handles adxWordEvents.DocumentOpen
        Enable_Save_Button()
        Dim opencount As Integer = 0
        Try
            For Each docname In WordApp.Documents
                If docname.name = WordApp.ActiveDocument.Name Then
                    opencount = opencount + 1
                End If
            Next
        Catch

        End Try


        If opencount > 1 Then
            MsgBox(txtOpenTwice, MsgBoxStyle.Critical, txtDialogTitle)
            WordApp.ActiveDocument.Close()
        End If

    End Sub



Regards

Thomas
Posted 13 Apr, 2012 07:47:26 Top
Andrei Smolin


Add-in Express team


Posts: 18794
Joined: 2006-05-11
Hi Thomas,

Are you saying that turning the Camtasia add-in off solves the problem?

I would recommend cleaning your code: there are many COM objects left unreleased in your code fragment. Not sure if this should help but who knows. 1) don't use foreach with COM objects, 2) WordApp.ActiveDocument as well as WordApp.Documents create COM objects that you should release. Pay attention to this blog: http://www.add-in-express.com/creating-addins-blog/2008/10/30/releasing-office-objects-net/


Andrei Smolin
Add-in Express Team Leader
Posted 13 Apr, 2012 08:17:52 Top
Thomas Bach


Guest


Hi Andrei,

yes, we disabled the camtasia addin and our code works.

Did you have any other hint for checking if an document is already opened?

I?ll check the entire code for unreleased com objects.

Tx

Thomas
Posted 13 Apr, 2012 08:22:39 Top
Andrei Smolin


Add-in Express team


Posts: 18794
Joined: 2006-05-11
Before you start modifying the code, I'd check whether the events occur if you intercept them in VBA. If they occur, then releasing COM objects will help you. Otherwise, it will not.


Andrei Smolin
Add-in Express Team Leader
Posted 13 Apr, 2012 08:38:05 Top