How do I create a custom image for a toolbar?

K

korrin.anderson

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!
 
K

korrin.anderson

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top