Monday, May 07, 2007

Add ToolTipText in CommandBar Controls

Display ToolTipText in CommandBar Controls

Sub Show_ToolTipText_In_Controls()


Dim oCB As CommandBar
Dim oCtl As CommandBarControl

On Error Resume Next

' Delete Existing Command Bar
CommandBars("MyProject").Delete

'Create New Command Bar
Set oCB = CommandBars.Add
oCB.Name = "MyProject"
oCB.AdaptiveMenu = True


Set oCtl = oCB.Controls.Add(Type:=msoControlButton)
oCtl.Caption = "Show Message Box"
oCtl.TooltipText = "This is a sample"
oCtl.OnAction = "Display_Msg_Box"
oCtl.SetFocus

' Show the Command Bar
oCB.Visible = True

' Place the CommandBar at the bottom of the screen
oCB.Position = msoBarBottom

End Sub

Sub Display_Msg_Box()

MsgBox "You have clicked me!!!"

End Sub

1 comment:

  1. Anonymous1:24 PM

    Hello,

    Just tried this piece of code and found one element missing:

    Set oCtl = oCB.Controls.Add(Type:=msoControlButton)
    oCtl.style = "msoButtonCaption"
    oCtl.Caption = "Show Message Box"
    oCtl.TooltipText = "This is a sample"
    oCtl.OnAction = "Display_Msg_Box"
    oCtl.SetFocus

    Without it the button caption won't appear; shows blank button, only

    ReplyDelete

StumbleUpon
Share on Facebook
Related Posts Plugin for WordPress, Blogger...
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.