Adding a CommandBarButton to the CommandBar
I am trying to create a COM Add-in for the MS Word and I wrote the following function of which I used to add a CommandBarButton to the "Web" CommandBar in the MS Word. When this function was called during the startup of MS Word in the OnStartupComplete(), the following error message displayed:
http://hk.geocities.com/saratara_me/errmsg.JPG
Could anybody please tell me what the problems could possibly be?
Many thanks to you all! :D
VB Code:
Public Function AddToCommandBar() As CommandBarButton
Dim cbb As CommandBarButton
Dim Cnt As Integer
Cnt = Application.CommandBars("Web").Controls.Count
Set cbb = Application.CommandBars("Web").Controls.Add(Type:=msoControlButton, Id:=2950, Before:=Cnt + 1)
Set AddToCommandBar = cbb
End Function