This project has moved and is read-only. For the latest updates, please go here.

Some problems when use Netoffice to create commandbar in word 2003

Apr 21, 2015 at 2:49 PM
Hello everyone, it's me again!

I use the NEToffice to create a project for Word Addin. And in the RibbonUI, it can load my settings. But when I try to create a commandbar for the compatible of word 2003, there are some problem.
First let me introduce what I have made change for the RibbonUI project.

In the Addin class, I define mCommandBar as my command bar
Private mCommandBar As Office.CommandBar
Then in the "CreateUserInterface" function, I add these sentences:
Private Sub CreateUserInterface()
    If Val(Application.Version) < 12 Then
            mCommandBar = Application.CommandBars.Add("EquationToolsNET", MsoBarPosition.msoBarTop, True, False)
            If mCommandBar IsNot Nothing Then
                Dim commandBtn1 As Office.CommandBarButton = mCommandBar.Controls.Add(MsoControlType.msoControlButton)
                With commandBtn1
                    .Caption = "NewEquation"
                    .FaceId = 26
                    .OnAction = "NewEquation_Click"
                    .Visible = True
                End With

                Dim commandBtn2 As Office.CommandBarButton = mCommandBar.Controls.Add(MsoControlType.msoControlButton)
                With commandBtn2
                    .Caption = "Crossreference"
                    .FaceId = 37
                    .OnAction = "CrossREF_Click"
                    .Visible = True
                End With

                Dim commandBtn3 As Office.CommandBarButton = mCommandBar.Controls.Add(MsoControlType.msoControlButton)
                With commandBtn3
                    .Caption = "ToolBox"
                    .FaceId = 176
                    .OnAction = "ToolBox_Click"
                    .Visible = True
                End With
                mCommandBar.Visible = True
            End If
        Catch extips As Exception
        End Try
    End If
End Sub
So, when the Addin is loaded int the word, the "Addin_OnStartupComplete" will run '"CreateUserInterface" and load my commandbar.

When I debug the project, word 2003 could add my commandbar, but add two commandbar!
Is there some ways to check the commandbar is already added?
What is so weird is even the Word 2003 run the first time, two commandbars will be added at the same time.

And here is another problem since the commandbar is loaded. When I click the button, the Word will send a notification windows which says it can't find the Macro or the Marco is disabled. So I change the Marco security setting as low security. But it still doesn't work.

What make it more strange is, when I debug the project with Word 2013, it can work correctly. So I just don't know why.

Any help will be appreciated! Thanks!
Apr 22, 2015 at 4:13 PM
I see no reason in your code why the commandbar is created 2x times.

my suggestions for now:

1.) may you have a dead ui element(commandbar, may you call Add before without the temporary:false argument). try load the office application without your addin and see a dead commandbar "EquationToolsNET" still exists. (you can remove this easily in the office application or the NO Developer Toolbox)

2.) make sure your addin is loaded only 1 times, check the registry Office/Word/Addins. May a previous addin version want load here

3.) Use the CommandBars.Find method before Add to make sure no duplicate item is created

4.) teamviewer session to help you directly :)

Apr 22, 2015 at 4:52 PM
Thank you very much!!!

But it's too late today, I'm in China, and it's 23:48 now, the dorm building will be closed. Can I contact you with my Email ( Send me a email, and I can transfer my codes to you.

Sincere thankfulness for you