Something wrong with the commandbar in Word 2003

Apr 28, 2015 at 3:02 AM
Hello, everyone!

I'm trying to make an Addin for word. And now I almost have done the things. But there still one problem here.

I try to make an Addin with compability with classicalUI and RibbonUI, so in the CreateUserInterface function, I added these codes:
Private Sub CreateUserInterface()
    If Not (Utils.ApplicationIs2007OrHigher) Then

        On Error Resume Next
        mCommandBar = Application.CommandBars("EquationToolsNET")
        If mCommandBar Is Nothing Then

            mCommandBar = Application.CommandBars.Add("EquationToolsNET")
            If mCommandBar IsNot Nothing Then
                mCommandBar.Visible = True

                Dim commandBarBtn As Office.CommandBarButton = mCommandBar.Controls.Add(MsoControlType.msoControlButton)
                Dim clickHandler As NetOffice.OfficeApi.CommandBarButton_ClickEventHandler = AddressOf Me.commandBarBtn_ClickEvent
                With commandBarBtn
                    .Caption = "NewEquation"
                    .FaceId = 26
                    .Visible = True
                    AddHandler .ClickEvent, clickHandler
                End With

                commandBarBtn = mCommandBar.Controls.Add(MsoControlType.msoControlButton)
                With commandBarBtn
                    .Caption = "CrossREF"
                    .FaceId = 37
                    .Visible = True
                    AddHandler .ClickEvent, clickHandler
                End With

                commandBarBtn = mCommandBar.Controls.Add(MsoControlType.msoControlButton)
                With commandBarBtn
                    .Caption = "ToolBox"
                    .FaceId = 176
                    .Visible = True
                    AddHandler .ClickEvent, clickHandler
                End With
            End If
        End If
    End If
End Sub
So when I debug this project in Word 2003 for the first time, the commandbar is added, the buttons can work correctly. But after the debug, I open the word 2003 again, the commandbar still exist, but the click actions don't work.

I think the problem is, the command button is not linked to the action sub functions, since the commandbar and buttons are added only at the first time, actions can work only in that case.

I know, I can add the commandbar again at the beginning time when the Word application starts, and delete it at the ending time when the Word application ends. But this is not what I want. I want the commandbar are added at the first time, at can work for the next time.

In the RibbonUI, the Group is added, and can work correctly for every time the Word starts.

Can anyone help me to solve this problem?

Thanks!!!
Apr 29, 2015 at 2:56 AM
Hello everyone!

About this problem, finally I solved it.
In order to keep the compatible with Word 2003, I have to add a commandbar. I searched on the internet and the tutorials, noticed the commandbar will be added while word starts, and it will be delete while shuts down. This is not I want, since the commandbar will be recreate for each time, its position and status information will be lost.

What I do, is to create and delete the commandbar's buttons for each time, not all the commandbar, just buttons. So the buttons' action operation will be re-linked to the sub function, and work correctly.

Thanks, anyway. I hope this will give others have the same problem some clue.