+ Reply to Thread
Results 1 to 4 of 4

How do I create a custom image for a toolbar?

  1. #1

    How do I create a custom image for a toolbar?

    The toolbar is being generated upon loading of the excel add-in via the
    following code:

    Set cmdRW = CommandBars.Add(Name:="DT")


    With cmdRW

    With .Controls.Add(Type:=msoControlButton)
    .TooltipText = "New Sheet"
    .OnAction = "Sheet"
    .FaceId = 98

    I know how to design a new button image when creating a toolbar
    manually, but how do I do so when creating the toolbar programtically?

    Thanks!


  2. #2

    Re: How do I create a custom image for a toolbar?

    I found the following code, however the image is not displaying in the
    toolbar, just a blank space...any help would be greatly appreciated!

    THanks


    Sub AddPictureToButton()

    Dim oShape As Shape

    'Place the graphic in the document
    Set oShape = ActiveDocument.Shapes.AddPicture(FileName:= _
    "PathAndNameOfPicture.gif")

    oShape.Select

    'Copy graphic
    Selection.CopyAsPicture

    'Delete from document
    Selection.Delete

    'Copy the graphic to the first button on your toolbar
    'Replace the name of the commandbar with your own
    CommandBars("TemplateCommandbar").Controls(1).PasteFace

    Set oShape = Nothing

    End Sub

    ---------------------------------------------------------------------------------------------------------

    [email protected] wrote:
    > The toolbar is being generated upon loading of the excel add-in via the
    > following code:
    >
    > Set cmdRW = CommandBars.Add(Name:="DT")
    >
    >
    > With cmdRW
    >
    > With .Controls.Add(Type:=msoControlButton)
    > .TooltipText = "New Sheet"
    > .OnAction = "Sheet"
    > .FaceId = 98
    >
    > I know how to design a new button image when creating a toolbar
    > manually, but how do I do so when creating the toolbar programtically?
    >
    > Thanks!



  3. #3

    Re: How do I create a custom image for a toolbar?

    I found the following code, however the image is not displaying in the
    toolbar, just a blank space...any help would be greatly appreciated!

    THanks


    Sub AddPictureToButton()

    Dim oShape As Shape

    'Place the graphic in the document
    Set oShape = ActiveDocument.Shapes.AddPicture(FileName:= _
    "PathAndNameOfPicture.gif")

    oShape.Select

    'Copy graphic
    Selection.CopyAsPicture

    'Delete from document
    Selection.Delete

    'Copy the graphic to the first button on your toolbar
    'Replace the name of the commandbar with your own
    CommandBars("TemplateCommandbar").Controls(1).PasteFace

    Set oShape = Nothing

    End Sub

    ---------------------------------------------------------------------------------------------------------

    [email protected] wrote:
    > The toolbar is being generated upon loading of the excel add-in via the
    > following code:
    >
    > Set cmdRW = CommandBars.Add(Name:="DT")
    >
    >
    > With cmdRW
    >
    > With .Controls.Add(Type:=msoControlButton)
    > .TooltipText = "New Sheet"
    > .OnAction = "Sheet"
    > .FaceId = 98
    >
    > I know how to design a new button image when creating a toolbar
    > manually, but how do I do so when creating the toolbar programtically?
    >
    > Thanks!



  4. #4
    JNW
    Guest

    RE: How do I create a custom image for a toolbar?

    Instead of
    .FaceId = 98

    Put...
    .Picture = LoadPicture("C:\My picture location")

    Note that only certain file types can be used (I don't remember off hand
    which ones don't work).

    JNW

    "[email protected]" wrote:

    > The toolbar is being generated upon loading of the excel add-in via the
    > following code:
    >
    > Set cmdRW = CommandBars.Add(Name:="DT")
    >
    >
    > With cmdRW
    >
    > With .Controls.Add(Type:=msoControlButton)
    > .TooltipText = "New Sheet"
    > .OnAction = "Sheet"
    > .FaceId = 98
    >
    > I know how to design a new button image when creating a toolbar
    > manually, but how do I do so when creating the toolbar programtically?
    >
    > Thanks!
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1