Dynamic Toolbar icon

G

Gregory Kip

I cannot find a way to paste an image into a now toolbar icon using VB
macros.

I create a toolbar button when I open a particular spreadsheet, and I
destroy it when I close the worksheet. In this way, my toolbar is customized
to the spreadsheet. But again I could not find a way to paste a new icon
onto the button using macros. Any help is appreciated. Please reply to the
group.
 
D

Die_Another_Day

Sub ChangeIcon()
Dim cb1 As CommandBarButton
Dim cBar As CommandBar
Set cBar = Application.CommandBars("Your Toolbar")
Set cb1 = cBar.Controls(Index of your control)
cb1.Picture = UserForm2.Image1.Picture 'or whatever picture you
want to assign
End Sub

HTH

Die_Another_Day
 
G

Guest

In all versions, if the icon is in the clipboard, then use pasteface. If it
isn't in the clipboard, then copy it first.

In xl2003 you can use the Picture property of the commandbarbutton. From
the help on that property:

Sub ChangeButtonImage()
Dim picPicture As IPictureDisp
Dim picMask As IPictureDisp

Set picPicture = stdole.StdFunctions.LoadPicture( _
"c:\images\picture.bmp")
Set picMask = stdole.StdFunctions.LoadPicture( _
"c:\images\mask.bmp")

'Reference the first button on the first command bar
'using a With...End With block.
With Application.CommandBars.FindControl(msoControlButton)
'Change the button image.
.Picture = picPicture

'Use the second image to define the area of the
'button that should be transparent.
.Mask = picMask
End With
End Sub
 

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