Hopefully, this is simple.
I am creating a toolbar using PPA macro under PP2003/2007. How can I add a specific image to the toolbar button? I am using the following code. I originally set it up to be a pig (FaceId 52) but don't know how to change that so that I can replace it with my own specific image/icon.
Thanks.
Code: Select all
Sub Auto_Open()
Dim oToolbar As CommandBar
Dim oButton As CommandBarButton
Dim MyToolbar As String
' Give the toolbar a name
MyToolbar = "ChangeColour"
On Error Resume Next
' so that it doesn't stop on the next line if the toolbar's already there
' Create the toolbar; PowerPoint will error if it already exists
Set oToolbar = CommandBars.Add(Name:=MyToolbar, Position:=msoBarTop, Temporary:=False)
If Err.Number <> 0 Then
' The toolbar's already there, so we have nothing to do
Exit Sub
End If
On Error GoTo ErrorHandler
' Now add a button to the new toolbar
Set oButton = oToolbar.Controls.Add(Type:=msoControlButton)
' And/set some of the button's properties
With oButton
.DescriptionText = "Change colour of the presentation" ' Tooltip text when mouse if placed over button
.Caption = "Change Colour" ' Text if Text in Icon is chosen
.OnAction = "ShowColourSelection" ' Runs ShowColourSelection macro when clicked
.Style = msoButtonIcon ' Button displays as icon, not text or both
.FaceId = 52 ' 52 is my favorite pig until Simon changes it
End With
' You can set the toolbar position and visibility here if you like
' By default, it'll be visible when created
oToolbar.Top = 150
oToolbar.Left = 150
oToolbar.Visible = True
NormalExit:
Exit Sub ' so it doesn't go on to run the errorhandler code
ErrorHandler:
'Just in case there is an error
MsgBox Err.Number & vbCrLf & Err.Description
Resume NormalExit:
End Sub