msoControlButton does not show until after customize

G

Grumpy

Word 2003

When I add a control button to the "Tools" menu the button does not appear
until I click on 'View -> Toolbars -> customize -> then open the 'Tools'
menu and then close the customize session.

What am I doing wrong please?

Sub AddMenu()

Dim myMenubar As CommandBar
Dim ACCRControl, ctl, myControl As CommandBarControl


Set myMenubar = CommandBars.ActiveMenuBar
Set myControl = myMenubar.Controls(6)

For Each ctl In myControl.Controls
If ctl.Caption = "Load ACCRs" Then
Exit Sub
End If
Next

Set ACCRControl = myControl.Controls.Add _
(Type:=msoControlButton, _
ID:=1, temporary:=False)

With ACCRControl
.Caption = "Load ACCRs"
.DescriptionText = "Loads ACCRs from list in table"
.OnAction = "LoadACCRs"
.Enabled = True
.Visible = True
End With

End Sub
 
T

Tony Jollans

The code works fine for me (Word 2003) and I can't see any obvious reason
why it shouldn't work. Although I wouldn't expect it, could it be that the
control is there and only shown in the full menu so that you don't see it
immediately when clicking on Tools?

I would just point out that ...
Dim ACCRControl, ctl, myControl As CommandBarControl

declares myControl as a CommandBarControl
and ACCRControl and ctl as Variants.
 
G

Grumpy

Thanks for the response and your point out.

I changed the declaration and everthing is OK. The control appears first
time everytime. I don't suppose I have to understand why.
Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top