Displaying CommandBar FaceID Images

If you create custom menus or toolbars, you’re probably familiar with the FaceId property — a numeric value that specifies an image. People have come up with lots of ways to display the FaceId images. Here’s one I haven’t seen before.

Start with an empty workbook, and paste the ShowFaceIDs procedure into a VBA module. Adjust the ID_START and ID_END constants to specify which images you’d like to see (it’s currently set up to show the first 500). Run the macro, and the 18 x 18 pixel images are displayed on the active worksheet. Click an image and you’ll see it’s FaceID value in the Name box.

Sub ShowFaceIDs()
    Dim NewToolbar As CommandBar
    Dim TopPos As Long, LeftPos As Long
    Dim i As Long, NumPics As Long

‘- – – – – Change These – – – – –
   Const ID_START As Long = 1
    Const ID_END As Long = 500
‘- – – – – – – – – – – – – – – – – – – –

‘   Delete existing TempFaceIds toolbar if it exists
   On Error Resume Next
    Application.CommandBars(“TempFaceIds”).Delete
    On Error GoTo 0

‘   Clear the sheet
   ActiveSheet.Pictures.Delete
    Application.ScreenUpdating = False
   
‘   Add an empty toolbar
   Set NewToolbar = Application.CommandBars.Add _
        (Name:=“TempFaceIds”)

‘   Starting positions
   TopPos = 5
    LeftPos = 5
    NumPics = 0
   
    For i = ID_START To ID_END
        On Error Resume Next
        NewToolbar.Controls(1).Delete
        With NewToolbar.Controls.Add(Type:=msoControlButton)
            .FaceId = i
            .CopyFace
        End With
        On Error GoTo 0
       
        NumPics = NumPics + 1
        ActiveSheet.Paste
        With ActiveSheet.Shapes(NumPics)
            .Top = TopPos
            .Left = LeftPos
            .Name = “FaceID “ & i
            .PictureFormat.TransparentBackground = True
            .PictureFormat.TransparencyColor = RGB(224, 223, 227)
        End With
       
‘       Update top and left positions for the next one
       LeftPos = LeftPos + 16
        If NumPics Mod 40 = 0 Then
            TopPos = TopPos + 16
            LeftPos = 5
        End If
    Next i
    ActiveWindow.RangeSelection.Select
    Application.CommandBars(“TempFaceIds”).Delete
End Sub

Even if you don’t create CommandBars, you might have fun looking at all the little pictures.

Posted in Uncategorized

14 thoughts on “Displaying CommandBar FaceID Images

  1. Hi John

    This is a great fun piece of code – my personal favourite has to be number 4000 (it’s a little doggie ;-) ). Thanks for sharing!

    Richard

  2. How about this
    Create 6 Commandbars, each contains 600 icons(FaceID)
    Cascading displayed, shows FaceID No when cursor
    move on it

    Sub AddButton()
    Dim GName As String
    Dim I As Integer, J As Single
    For I = 6 To 1 Step -1 ‘ Display from bottom to top
    GName = “Group” & 600 * (I – 1) + 1 & “_” & 600 * I
    On Error GoTo Endline
    With Application.CommandBars.Add(GName)
    .Visible = True
    With .Controls
    For J = 600 * (I – 1) + 1 To 600 * I
    On Error Resume Next
    With .Add(msoControlButton)
    .FaceId = J
    .Caption = J
    End With
    Next
    End With
    End With
    Endline:
    With CommandBars(GName)
    .Visible = True
    .Width = 720 ‘ contains 30×20 icons
    .Left = 50 + (6 – I) * 20
    .Top = 90 + (6 – I) * 20
    End With
    Next I
    End Sub

  3. There’s a lot to choose but is there a way that i can make my own images by VBA?
    I don’t want to send an image with my macro’s but my macro must build an image!
    (example: 1st pixel: grey, 2nd pixel: red etc.)
    Do you think that can make an image with VBA??

  4. There’s a lot to choose but is there a way that i can make my own images by VBA?
    I don’t want to send an image with my macro’s but my macro must build an image!
    (example: 1st pixel: grey, 2nd pixel: red etc.)
    Do you think that you can make an image with VBA??

  5. Jerry, your technique is the one that’s most-often used. But try it in Excel 2007. Not a pretty sight. You get three rows of icons, and you have to scroll horizontally 25 times to see them all. That was my motivation to show them on a worksheet.

    Although FaceID images don’t have much use in Excel 2007, I still like to use them sometimes for images on UserForm controls.

  6. Yes, they redesign the icons from time to time. The icons for the Office programs change slightly each version, and the whole collection of icons got facelifts (face-ID-lifts?) for Office 2003. I hadn’t noticed that the 2003 icons were affected by the Office 2007 installation on the same machine.

  7. All FaceID browsers that I know are based on Commandbars and therefore most of them, or all, don’t work well in XL 2007. Since I’ve started creating a set of routines to build commandbar like userforms in order to replace my old custom commandbars for XL 2007, I felt that one of the first things that will come handy would be to have a faceID browser based on a Userform. Basically trivial but it took a while to figure out how to get the faceID’s clean and relatively simple onto on image control in a userform.

    If you’re interested send me an email, or just follow these simple steps:
    – create a new userform
    – put 4 commandbarbuttons on it, size and position doesn’t matter, w/ std. system names “CommandButton1? and so on.

    put all the following code into the code module of the newly created userform.
    run it and be happy to have another faceID browser in your collection.
    ‘————————————————
    Option Explicit
    Dim currentFaceIDstart As Integer

    Private Sub UserForm_Initialize()
    SetupCmdButtons
    Create500Images
    currentFaceIDstart = 1
    SetFaces 4, currentFaceIDstart, 500
    End Sub

    Private Sub SetupCmdButtons()
    If Controls.count 4 Then
    MsgBox “There need to be 4 CommandButtons on this form. Not more and not less. Modify and try again!”
    Unload Me
    End If

    Dim i As Integer
    For i = 1 To 4
    With Me.Controls(i – 1)
    .Top = 1
    .Left = i * 18 + 118
    .Width = 18
    .Height = 18
    End With
    Next i
    SetFaces 0, 154, 4
    Controls(0).ControlTipText = “Start at 1?
    Controls(1).ControlTipText = “back”
    Controls(2).ControlTipText = “forward”
    Controls(3).ControlTipText = “goto last gallery”
    End Sub

    Private Sub CommandButton1_Click()
    If currentFaceIDstart 1 Then
    currentFaceIDstart = 1
    SetFaces 4, currentFaceIDstart, 500
    End If
    End Sub

    Private Sub CommandButton2_Click()
    If currentFaceIDstart > 500 Then
    currentFaceIDstart = currentFaceIDstart – 500
    If currentFaceIDstart = 8501 Then currentFaceIDstart = 7501
    If currentFaceIDstart = 5001 Then currentFaceIDstart = 4001
    SetFaces 4, currentFaceIDstart, 500
    End If
    End Sub

    Private Sub CommandButton3_Click()
    If currentFaceIDstart < 10001 Then
    currentFaceIDstart = currentFaceIDstart + 500
    If currentFaceIDstart = 8001 Then currentFaceIDstart = 9001
    If currentFaceIDstart = 4501 Then currentFaceIDstart = 5501
    If currentFaceIDstart = 10001 Then
    SetFaces 4, currentFaceIDstart, 100
    Else
    SetFaces 4, currentFaceIDstart, 500
    End If
    End If
    End Sub

    Private Sub CommandButton4_Click()
    currentFaceIDstart = 10001
    SetFaces 4, currentFaceIDstart, 100
    End Sub

    Private Sub Create500Images()
    Dim i As Integer
    Dim j As Integer
    Dim jten As Integer
    Dim n As Integer

    Me.Height = 498
    Me.Width = 352
    For i = 1 To 25
    jten = 1
    For j = 1 To 20
    With Me.Controls.Add(“Forms.Image.1?)
    .Top = (i – 1) * 17 + Fix(n / 100) * 6 + 20
    .Left = (j – 1) * 17 + jten
    .Width = 18
    .Height = 18
    .BorderColor = vbButtonShadow
    .BackColor = Me.BackColor
    End With
    n = n + 1
    If j = 10 Then jten = 3
    Next j
    Next i
    End Sub

    Private Sub SetFaces(FirstCtrlID As Integer, start As Integer, count As Integer)
    Dim i As Integer
    Dim j As Integer
    ‘From Microsoft Office xx.x Object Library
    Dim oBtn As Office.CommandBarButton
    ‘From Microsoft Windows Common Controls 6.0
    Dim oImgList(0 To 1) As MSComctlLib.ImageList

    Me.Height = count * 0.91 + 42
    Me.Caption = “MS Office/Excel FaceID’s ” & _
    CStr(start) & ” – ” & CStr(start + count – 1)

    On Error Resume Next
    CommandBars(“FaceIDcmdbar”).Delete
    On Error GoTo 0
    With CommandBars.Add(“FaceIDcmdbar”, , , True)
    Set oBtn = .Controls.Add(msoControlButton, , , , True)
    End With
    For i = 0 To 1
    Set oImgList(i) = New ImageList
    With oImgList(i)
    .ImageHeight = 16
    .ImageWidth = 16
    .UseMaskColor = True
    .MaskColor = IIf(i = 0, vbWhite, vbBlack)
    .BackColor = IIf(i = 0, vbButtonFace, vbBlack)
    End With
    Next
    On Error Resume Next

    For i = start To start + count – 1
    oBtn.FaceId = i
    With oImgList(0).ListImages
    .Clear
    .Add 1, “M”, oBtn.Mask
    End With
    With oImgList(1).ListImages
    .Clear
    .Add 1, “MM”, oImgList(0).Overlay(“M”, “M”)
    .Add 2, “P”, oBtn.Picture
    End With
    With Me.Controls(FirstCtrlID + j)
    .Picture = oImgList(1).Overlay(“P”, “MM”)
    .ControlTipText = CStr(i)
    End With
    j = j + 1
    Next i
    End Sub

  8. @Hartmut – Very nice browser, but the single quotes, double quotes, negative signs got mangled by the paste. The not equals (GreaterThan-LessThan) where you check control count got removed.

    Has anyone found a site with a text description of each faceid?

Leave a Reply

Your email address will not be published. Required fields are marked *