How to add a custom toolbar button and give it a tooltip

Bob asked in the comments on this article if it's possible to add a tooltip to a button. Here's one way to do it programmatically for your own buttons. The below example adds a custom button to the standard toolbar and assigns it a tooltip. Note that the button does not actually do anything in this sample - in order to make it do anything, you'd need to change “NameOfFunctionToCallOnClick“ in the first sub below to call your own macro.

First, follow the instructions in this article with this code:

Sub AddCustomButton()
'Adds a custom button to the standard toolbar if it's not there already.
'Clicking on this button calls a custom action that would have to be
'defined in a separate sub, see the .OnAction line below.
Dim cbb As CommandBarButton
Dim cbStandard As CommandBar
Dim cbExist As Boolean

'The Standard toolbar is the one with "New", "Send/Receive", etc on it.
Set cbStandard = ActiveExplorer.CommandBars("Standard")
cbExist = IsMenuThere("Standard", "CustomButton")

'If the option is not already on the menu, add it
If cbExist = False Then
Set cbb = cbStandard.Controls.Add(msoControlButton)
cbb.Caption = "Custom&Button"
cbb.OnAction = "NameOfFunctionToCallOnClick"
cbb.TooltipText = "Tooltip for this button"
End If

Set cbb = Nothing
Set cbEdit = Nothing
Set cbStandard = Nothing

End Sub

Public Function IsMenuThere(sMenu As String, sName As String) As Boolean
'Returns true if menu sName exists in sMenu
Dim cbb As CommandBar
Dim cbControl As CommandBarControl

IsMenuThere = False

Set cbb = ActiveExplorer.CommandBars(sMenu)

'Cycles through the given commandbar, checking the captions to see
'if they match the one we're looking for
For Each cbControl In cbb.Controls
If cbControl.Caption = sName Then
IsMenuThere = True
Exit Function
End If

Set cbb = Nothing
Set cbControl = Nothing

End Function

Note: The IsMenuThere function comes from Outlook MVP Ken Slovak's Outlook 2000 programming book. I read it many years ago while teaching myself how to write code in Outlook, and I have used it countless times since then. Highly recommended book; very readable and easy to pick and choose parts out of it to learn what you want to learn (I picked it up with the goal of finding out how to add a toolbar button programmatically for example =).