title: VBA: Create an in memory bitmap to display as icon on commandbarbutton
body: <p>In VBA I've created a custom commmandbar with buttons that allow me to set the background color of a selection of lines in my MS Project planning.</p>
  
  <p>Instead of using text captions, I'd like to display 16x16 bitmap icons with the appropriate color on each button. I can load these bitmaps from the hard disk, but would like to create them in VBA. </p>
  
  <p>Is this possible? There is no bitmap or drawing class in VBA afaik after my extensive research.</p>
  
  <p>What it is now:</p>
  
  <p><img src="https://i.stack.imgur.com/W22Ov.png" alt="enter image description here"></p>
  
  <p>What it should become (manually done):</p>
  
  <p><img src="https://i.stack.imgur.com/T4RlE.png" alt="enter image description here"></p>
  
  <p>Code:</p>
  
  <pre><code>'1 red
  '2 yellow
  '3 green
  '4 blue
  '5 dark blue
  '6 fushia
  '7 white
  
  Sub createcolorbar()
  
      Dim cbar As CommandBar
      Dim cctrl As CommandBarButton
  
      On Error Resume Next
      CommandBars("Colors").Delete
  
      Set cbar = CommandBars.Add("Colors")
      cbar.Visible = True
      cbar.Position = msoBarTop
  
      With cbar
      'white
          Set ctrl = .Controls.Add(msoControlButton, , , , True)
          With ctrl
              .BeginGroup = True
              .Caption = "White"
              .State = msoButtonUp
              .Style = msoButtonIconAndCaption 'change for icon
              .OnAction = "Macro ""color_white"""
              '.FaceId = 59 'Smiley
              .Picture = stdole.StdFunctions.LoadPicture("c:\Temp\a.bmp")
          End With
           ' red
          Set ctrl = .Controls.Add(msoControlButton, , , , True)
          With ctrl
              .BeginGroup = True
              .Caption = "Red"
              .State = msoButtonUp
              .Style = msoButtonCaption
              .OnAction = "Macro ""color_red"""
          End With
          'yellow
          Set ctrl = .Controls.Add(msoControlButton, , , , True)
          With ctrl
              .BeginGroup = True
              .Caption = "Yellow"
              .State = msoButtonUp
              .Style = msoButtonCaption
              .OnAction = "Macro ""color_yellow"""
          End With
          'green
          Set ctrl = .Controls.Add(msoControlButton, , , , True)
          With ctrl
              .BeginGroup = True
              .Caption = "Green"
              .State = msoButtonUp
              .Style = msoButtonCaption
              .OnAction = "Macro ""color_green"""
          End With
          'blue
          Set ctrl = .Controls.Add(msoControlButton, , , , True)
          With ctrl
              .BeginGroup = True
              .Caption = "Blue"
              .State = msoButtonUp
              .Style = msoButtonCaption
              .OnAction = "Macro ""color_blue"""
          End With
          'Darkblue
          Set ctrl = .Controls.Add(msoControlButton, , , , True)
          With ctrl
              .BeginGroup = True
              .Caption = "Darkblue"
              .State = msoButtonUp
              .Style = msoButtonCaption
              .OnAction = "Macro ""color_darkblue"""
          End With
          'fushia
          Set ctrl = .Controls.Add(msoControlButton, , , , True)
          With ctrl
              .BeginGroup = True
              .Caption = "Fushia"
              .State = msoButtonUp
              .Style = msoButtonCaption
              .OnAction = "Macro ""color_fushia"""
          End With
      End With
      Set ctrl = Nothing
  
  End Sub
  
  Sub color_x(x)
      Set ts = ActiveSelection.Tasks
      For Each tsk In ts
          FontEx CellColor:=x
      Next tsk
  End Sub
  
  Sub color_red()
      Call color_x(1)
  End Sub
  
  Sub color_yellow()
      Call color_x(2)
  End Sub
  
  Sub color_green()
      Call color_x(3)
  End Sub
  
  Sub color_blue()
      Call color_x(4)
  End Sub
  
  Sub color_darkblue()
      Call color_x(5)
  End Sub
  
  Sub color_fushia()
      Call color_x(6)
  End Sub
  
  Sub color_white()
      Call color_x(7)
  End Sub
  </code></pre>