Caption on CommandBarButton

A

Al

Hi All,

I have the following code which is in a template in the startup folder.

It adds a button to the word command bar.

For some damn reason the actual text on the button is not displaying.

Anyone see why? I am in Office 2003.

Cheers

-Al

Sub Autoexec()
'install the button
Dim ctl As Office.CommandBarControl 'where the button will be
Dim ctlButton As Office.CommandBarButton
'before adding the button, verify if it is already installed ...
Set ctl =
CommandBars("standard").Controls(CommandBars("standard").Controls.Count)
If ctl.Caption <> "Caption Summary" Then
Set ctlButton = CommandBars("Standard").Controls.Add
With ctlButton
.Caption = "Caption Summary"
.TooltipText = "Click to start an arrest file set"
.OnAction = "Modification" 'the procedure to be call when a
click ...
End With
Else
'we are adding nothing to the toolBar, it is already here
End If
End Sub

Private Sub Modification() 'the sub where you handle the click event on the
Button
MsgBox "It works"
End Sub
 
P

Peter Hewett

Hi Al

I haven't tried out your code but I can't see where you set the
CustomizationContext.

If you're executing code in your Normal template it doesn't matter. If
you're executing code in your Add-In then it does! Try this:

Sub Context()
Dim objOriginalContext As Object

Set objOriginalContext = CustomizationContext
CustomizationContext = ThisDocument

' Your code here

CustomizationContext = objOriginalContext
End Sub

Note that the code restores the original context.

HTH + Cheers - Peter
 
P

Peter Hewett

Hi Al

Sorry I fogot to add:

Your code assumes that the command bar you add will always be the last in
the collection. I don't think this is a safe long-term assumption. I'd
iterate the Controls collection until you find the one you want.

HTH + Cheers - Peter
 
T

Tom Winter

You need to locate your buttons based on the TAG property. Use one of the
FIND methods:

CommandBar.FindControl(Tag:="MyTag")

You need to set the STYLE property:

..Style = msoButtonIconAndCaption
 
A

Al

Yeah it worked Thanks guys. I think it was the style option that was getting
me.

-Al
 

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