Change toolbar icon in VBA

P

Paul

I want to set a collection of icons into a toolbar, but I want to use
specific icon images.

How do I set them in VBA ?
Is there a list of the icon ID's with their images I can select from ?
(again set in VBA)
Can I use external icon files ?
 
S

Sam Wilson

Hi,

If you want to use built in ones, you need to look at "FaceId" in help.
There are absolutely thousands of them... This will show them all, but it's
not fast.

Sub faces()

Dim i As Integer
Dim cont As CommandBarControl
Dim bar As CommandBar

On Error GoTo catcher

Application.ScreenUpdating = False
Set bar = CommandBars.Add(Position:=msoBarFloating, MenuBar:=False,
temporary:=True)
Set cont = bar.Controls.Add(Type:=msoControlButton, temporary:=True)

Do
cont.FaceId = i
cont.CopyFace
ActiveSheet.Paste Cells(i + 1, 1)
i = i + 1
Loop

catcher:
If Err.Number = 1004 Then Resume Next
bar.Delete

End Sub

you can set them in your code by declaring a commandbarcontrol and then
setting its faceid property.

Sam
 

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