Announcement

Collapse
No announcement yet.

VBA: faceID - how to have more choice of button images?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBA: faceID - how to have more choice of button images?



    Hi,

    If I want to have more button images to attach to my menus in addition to the default Excel button images, how would I do that ?

    Appreciate your help and thanks !

  • #2
    You might try to import pictures on the places you want your buttons. You can give images some properties as well in vba:

    Private Sub Image1_Click()
    (your code)
    End Sub

    Good luck!

    Mathijs - The Netherlands

    Comment


    • #3


      Hi a,

      Instead of using the inbuilt FaceIds you can paste your own pictures into a sheet, give them a meaningful name, and then use the PasteFace command in your code.

      I've pasted an example menu routine below:
      Code:
      Const cCommandBarID As String = "my Command Bar", cBtn1Sub As String = "MySub"
      Const cBtn2Sub As String = "MySub2", cBtn3Sub As String = "MySub3"
      
      Sub CreateCM()
          Dim cbBar As CommandBar, cbCtrl As CommandBarControl, cbPop As CommandBarPopup
          
          DeleteCM
          Set cbBar = CommandBars.Add(Name:=cCommandBarID, Position:=msoBarTop)
          
          Set cbCtrl = cbBar.Controls.Add(Type:=msoControlButton)
          With cbCtrl
              .FaceId = 59            'Smiley Face Id
              .OnAction = cBtn1Sub
              .Style = msoButtonIcon
          End With
          
          Set cbPop = cbBar.Controls.Add(Type:=msoControlPopup)
          'add a popup menu to the custom menu
          With cbPop
              .Caption = "PopCaption"
              .BeginGroup = True
          End With
          
          Set cbCtrl = cbPop.Controls.Add(Type:=msoControlButton)
          With cbCtrl
              .OnAction = cBtn2Sub
              .Style = msoButtonIconAndCaption
              .Caption = "YourCaption"
              Sheet1.Shapes("PicName").Copy       'use your own picture for the Face
              .PasteFace
          End With
          
          Set cbCtrl = cbPop.Controls.Add(Type:=msoControlButton)
          With cbCtrl
              .OnAction = cBtn3Sub
              .Style = msoButtonCaption
              .Caption = "YourCaptionHere"
          End With
          
          cbBar.Visible = True
          'make it visible
          
          Set cbBar = Nothing
          Set cbCtrl = Nothing
          'free memory
          
      End Sub
      
      Sub DeleteCM()
          Dim cbBar As CommandBar
          
          On Error Resume Next
          Set cbBar = CommandBars(cCommandBarID)
          cbBar.Delete
          Set cbBar = Nothing
      
      End Sub
      
      Sub MySub()
          MsgBox "Add the desired macro here!"
      End Sub
      Sub MySub2()
          MsgBox "Add the desired macro here!"
      End Sub
      Sub MySub3()
          MsgBox "Add the desired macro here!"
      End Sub
      As regards actually making your own pictures, I find that a simple icon editor (16x16) is the easiest method.

      HTH
      Cross-poster? Read this: Cross-posters
      Struggling to use tags (including Code tags)? : Forum tags

      Comment

      Working...
      X