PDA

View Full Version : Custom Toolbar - Custom Icons Issue



Sowanso
08-30-2006, 03:34 AM
Hello there,
I am trying to create custom toolbar with custom Icons on it. But that's where I've got stuck.

At first I tried frequent approach with creating the toolbar within the VBA code. Pictures were previously stored in a worksheet, so I just copied them and used .pasteFace procedure. But it doesn't work very well, since the icons lost their transparency and got awfully blurred.

So I moved on to the Toolbar Control combined with the ImageList as described e.g. here (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconusingimagecombocontrol.asp) . But the problem is that even if I set everything in the ImageList, I am not able to locate it within the Toolbar preferences. The rolldown menu just states there is no ImageList to choose from. In the button settings page the Image input is therefore disabled.

Therefore I tried to assign the ImageList to the Toolbar manually by the code using Toolbar.ImageList = ImageList1 and when nothing happened I tried to assign the picture to the button manually using Toolbar.Buttons.Item(1).Image = ImgList.ListImages(1).Picture. But even this approach gives me Invalid Key RunTime Error '35603'.

Do you have any ideas?

lior03
08-30-2006, 03:48 AM
Sub cmd()
Dim ocb As CommandBar
Dim newbtn As CommandBarButton
Set ocb = Application.CommandBars.add(name:="johnske", temporary:=True)
With ocb
.Position = msoBarTop
.Visible = True
End With
Set newbtn = ocb.Controls.add(Type:=msoControlButton)
With newbtn
.FaceId = 375
.OnAction = "vin1"
.Caption = "filter data"
.BeginGroup = True
End With
Set newbtn = ocb.Controls.add(Type:=msoControlButton)
With newbtn
.FaceId = 325
.OnAction = "findafile"
.Caption = "open a file"
.BeginGroup = True
End With
Set newbtn = ocb.Controls.add(Type:=msoControlButton)
With newbtn
.FaceId = 469
.OnAction = "sortworksheets"
.Caption = "sort ws"
.BeginGroup = True
End With
Set newbtn = ocb.Controls.add(Type:=msoControlButton)
With newbtn
.FaceId = 353
.OnAction = "lookfor_demo2"
.Caption = "partial text"
.BeginGroup = True
End With
Set newbtn = ocb.Controls.add(Type:=msoControlButton)
With newbtn
.FaceId = 383
.OnAction = "nnnn"
.Caption = "update comments"
.BeginGroup = True
End With
Set newbtn = ocb.Controls.add(Type:=msoControlButton)
With newbtn
.FaceId = 384
.OnAction = "rowme3"
.Caption = "shade altenate rows"
.BeginGroup = True
End With
Set newbtn = ocb.Controls.add(Type:=msoControlButton)
With newbtn
.FaceId = 395
.OnAction = "horin"
.Caption = "accounting format"
.BeginGroup = True
End With
Set newbtn = ocb.Controls.add(Type:=msoControlButton)
With newbtn
.FaceId = 386
.OnAction = "finders44"
.Caption = "find text"
.BeginGroup = True
End With
Set newbtn = ocb.Controls.add(Type:=msoControlButton)
With newbtn
.FaceId = 387
.OnAction = "closeallbut"
.Caption = "closeallbut"
.BeginGroup = True
End With
Set newbtn = ocb.Controls.add(Type:=msoControlButton)
With newbtn
.FaceId = 396
.OnAction = "daphnebook"
.Caption = "vbaexpress"
.BeginGroup = True
End With
End Sub

Sowanso
08-30-2006, 04:26 AM
I know this approach, but I need to use my own icons. Or is there any way how to add new icons to the default set from which I am taking the face by its id? As I said before for this case I tried to copy the icon into the clipboard and using .PasteFace assign it to the particular button.

SherryO
01-03-2007, 06:59 AM
As this is old, I'm not sure this will be of any help... I had the same problem and what I had to do to get the images recognized was put them on the active sheet and have them all selected before the pasteface. It worked for me, but they were still a little blurry, but not bad.

JonPeltier
01-03-2007, 08:15 AM
If the problem is blurry pictures, you should use Excel's CopyPicture method to copy them as bitmaps, not just the default Copy method.

wksht.Pictures(sPicName).CopyPicture xlScreen, xlBitmap
ctrl.PasteFace

The pictures need not be on the active sheet nor preselected, just properly referenced.

If you are having trouble with transparency etc and it's Office 2002 or later, you can use the .Picture and .Mask properties of the control, as described among other places here

http://support.microsoft.com/kb/286460
http://msdn2.microsoft.com/en-us/library/aa201298(office.11).aspx

and also in the excellent book Professional Excel Development by Bullen, Bovey, and Green. This book shows how to do it with embedded pictures, while the MS articles use bitmap files.

SherryO
01-03-2007, 08:17 AM
Thanks