[FAQ's: OD] How do I assign a standard Office image to a menu item or toolbar button?
To assign a custom menu item or toolbar button a built in default image you need to obtain the FaceId number of the desired image first.
Once you have your FaceId you can assign it to your menu item or toolbar button by setting its .FaceId property.
The CommandBarButton FaceId numbers of the CommandBars collection in any Office app can be found easily using code like shown below.
Word 2003 VBA Code Example:
VB Code:
Option Explicit
'Make sure you have Macros enabled
Private Sub Document_Open()
On Error Resume Next
Dim oCB As CommandBar
Dim oCBB As CommandBarButton
Dim i As Integer
Dim ii As Integer
Open "C:\FaceIds.txt" For Output As #1
Print #1, Application.Name & " Command Bar Button FaceIds"
Print #1,
For i = 1 To Application.CommandBars.Count
Set oCB = Application.CommandBars(i)
For ii = 1 To oCB.Controls.Count
Set oCBB = oCB.Controls(ii)
Print #1, "Bar Name: [" & oCB.Name & "] Button Caption: [" & oCBB.Caption & "] ID: [" & oCBB.ID & "]"
Next
Set oCBB = Nothing
Next
Set oCB = Nothing
Close #1
'Optionally you can open the textfile
If Dir("C:\FaceIds.txt") <> vbNullString Then
Shell "C:\FaceIds.txt", vbMaximizedFocus
End If
End Sub
'Example Output File Contents:
'Microsoft Word Command Bar Button FaceIds
'Bar Name: [Standard] Button Caption: [New &Blank Document] ID: [2520]
'Bar Name: [Standard] Button Caption: [&Open...] ID: [23]
'Bar Name: [Standard] Button Caption: [&Save] ID: [3]
'Bar Name: [Standard] Button Caption: [Permission (Unrestricted Access)] ID: [9004]
'Bar Name: [Standard] Button Caption: [&Mail Recipient] ID: [3738]
'Bar Name: [Standard] Button Caption: [&Print] ID: [2521]
'Bar Name: [Standard] Button Caption: [Print Pre&view] ID: [109]
'Bar Name: [Standard] Button Caption: [&Spelling and Grammar...] ID: [2566]
'Bar Name: [Standard] Button Caption: [&Research...] ID: [7343]
'Bar Name: [Standard] Button Caption: [Cu&t] ID: [21]
'Bar Name: [Standard] Button Caption: [&Copy] ID: [19]
'Bar Name: [Standard] Button Caption: [&Paste] ID: [22]
'...
'...
'...
Now that you have your list of FaceId numbers you can choose one for your custom menu item or toolbar button.
Word 2003 VBA Code Example:
VB Code:
Option Explicit
Public WithEvents oCBBCustom As Office.CommandBarButton
Private Sub oCBBCustom_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
MsgBox "Meow!!!"
End Sub
Private Sub Document_Open()
Dim oCB As Office.CommandBar
Dim oCBBTools As Office.CommandBarPopup
Set oCB = Application.CommandBars("Menu Bar")
Set oCBBTools = oCB.Controls("&Tools")
Set oCBBCustom = oCBBTools.Controls.Add(msoControlButton, 1, , , True) 'Place our custom one at the bottom
With oCBBCustom 'position (0 based)
.Caption = "Meow!"
.BeginGroup = True 'Add a line separator
.Enabled = True
.FaceId = 263 'Excel Image
.Visible = True
End With
'oCB.Reset 'To reset the menu.
End Sub
http://www.vbforums.com/attachment.p...chmentid=47113