Quantcast
Channel: NetOffice - MS Office in .NET
Viewing all articles
Browse latest Browse all 1741

New Post: Something wrong with the commandbar in Word 2003

$
0
0
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!!!

Viewing all articles
Browse latest Browse all 1741

Trending Articles