Please help, this is driving me nuts!!
I want to add custom images to a toolbar button. Easy if you do it manually, but i want my add-in to install buttons with custom images during install.
I've pinched the following code from VB Help in the editor (IIRC). However, i can't get it to run. It errors on the line where it's locating the image (set oShape=...), with the following message.
"runtime error '424' - Object required"
My first reaction was that the location/image name was wrong. But it isn't.
I've also made sure that the images are compatible. 16x16 pixels. In fact i created them in excel and exported them. I've tried making them bitmaps/gif's/jpegs with no luck.
I'm hoping i've missed something obvious, that somebody will point out to me. Or show me another way to achieve this.
thanks
I want to add custom images to a toolbar button. Easy if you do it manually, but i want my add-in to install buttons with custom images during install.
I've pinched the following code from VB Help in the editor (IIRC). However, i can't get it to run. It errors on the line where it's locating the image (set oShape=...), with the following message.
"runtime error '424' - Object required"
My first reaction was that the location/image name was wrong. But it isn't.
I've also made sure that the images are compatible. 16x16 pixels. In fact i created them in excel and exported them. I've tried making them bitmaps/gif's/jpegs with no luck.
I'm hoping i've missed something obvious, that somebody will point out to me. Or show me another way to achieve this.
thanks
Code:
Sub AddPictureToButton()
Dim oShape As Shape
Dim customBar As CommandBar
'Place the graphic in the document
Set oShape = ActiveDocument.Shapes.AddPicture("c:\buttons\test.gif")
Set customBar = Application.CommandBars("Toolbar")
oShape.Select
'Copy graphic
Selection.CopyAsPicture
'Delete from document
Selection.Delete
'Copy the graphic to the first button on the toolbar
customBar.Controls(1).PasteFace
Set oShape = Nothing
End Sub