Results 1 to 6 of 6
  1. #1
    Lounger
    Join Date
    Apr 2002
    Location
    Wellington, Wellington, New Zealand
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Excel - add custom image to a toolbar (2002)

    I have an add-in that all our users load and I am amending it to create a custom toolbar and assign a macro to it. We used to do this manually for each user!!!!!. I have the toolbar creating OK but I have a .bmp file that we normally paste as the button image. How do I do this programatically in the add-in. I have found the PasteFace command but am unsure how to get the bitmap onto the clipboard. Can anyone help...

    Sub Create_ToolBar()
    Dim customBar As CommandBar
    Dim newButton As CommandBarButton
    Set customBar = CommandBars.Add("DocsFooter", Position:=msoBarTop, _
    Temporary:=True)
    Set newButton = customBar.Controls _
    .Add(Type:=msoControlButton)
    With newButton
    .PatseFace
    .OnAction = "DocNum"
    End With
    customBar.Visible = True
    End Sub

    Thanks
    Belinda

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Excel - add custom image to a toolbar (2002)

    You can store a toolbar in a workbook, see the Toolbars tab of the Customize dialog. You will have to turn the IsAddin property of your add-in off temporarily to do so.

    With the toolbar stored in the add-in, you may not have to create a new toolbar every time. Or if you still prefer to do so, you can keep the toolbar in the add-in hidden, and use CopyFace to copy a button image to the clipboard.

  3. #3
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Excel - add custom image to a toolbar (2002)

    Here's a kludgy way I picked up from someone here on the Lounge a LONG time back, that you MAY be able to adapt:

    Sub PastePix()
    Dim cbrToolbar As CommandBar, cbtButton As CommandBarButton
    On Error Resume Next
    Application.CommandBars("Hack").Delete ' reset if preexisting
    Set cbrToolbar = Application.CommandBars.Add(Name:="Hack", Position:=msoBarTop)
    Set cbtButton = cbrToolbar.Controls.Add(Type:=msoControlButton)
    cbrToolbar.Visible = True
    ActiveSheet.Pictures.Insert("c:my picturescolprinter.bmp").Copy
    cbtButton.PasteFace
    ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Cut
    End Sub

    I'd give credit if the Search facility was working.
    -John ... I float in liquid gardens
    UTC -7ąDS

  4. #4
    Lounger
    Join Date
    Apr 2002
    Location
    Wellington, Wellington, New Zealand
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Excel - add custom image to a toolbar (2002)

    Thanks for the quick response, I will try this out as it may be more efficient than creating the toolbar each time...

    Belinda

  5. #5
    Lounger
    Join Date
    Apr 2002
    Location
    Wellington, Wellington, New Zealand
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Excel - add custom image to a toolbar (2002)

    Thanks for that, I thought I had seen some code in the lounge somewhere but without the search, I couldn't find it!. If Hans suggestion to add the toolbar to the add-in doesn't pan out I will try your code

    Belinda

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Excel - add custom image to a toolbar (2002)

    Have a look at <post#=200526>post 200526</post#>, it may give some idea's.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •