PDA

View Full Version : Edit Button images



VishalkumarT
09-20-2007, 03:49 AM
Dear Friends

I got some incredible help from this forum regarding Excel pgming, and my knowledge and interest in prgming has increased due to the same.

So thank you very much.

After playing with GUI components, I need to know If i have placed 2-3 buttons in a controlbar, which enable different macros assigned to them respectively, then how can I edit the images of this buttons ? I mean I tried to go to "Customize" with right-click on any button, then to Macro-buttons and then to edit their image, but once i edit it, after closing the worksheet and reopening it, buttons come with the same images, not with the edited.

I have placed the buttons with following code,

Application.CommandBars("MyCtrlBar").Controls.Add Type:=msoControlButton, ID:=2950

Application.CommandBars("MyCtrlBar").Controls.Add Type:=msoControlButton, ID:=2950, Before:=1

Application.CommandBars("MyCtrlBar").Controls.Add Type:=msoControlButton, ID:=2950, Before:=2


Now I want these three buttons with different images.

hope I have explained the querry correctly.

Thanks in advance
Vt

Bob Phillips
09-20-2007, 04:08 AM
You can assign a faceid



With Application.CommandBars("MyCtrlBar").Controls.Add(Type:=msoControlButton, ID:=2950)
.FaceId = 29
End With


See http://www.j-walk.com/ss/excel/tips/tip40.htm for avaiulable faceids

VishalkumarT
09-20-2007, 04:52 AM
That is amazing and unbelievably fast reply.

Is it any way to put a custom text in such faceid ? suppose I have blank image with faceid number 3519, and I want to display a text in this blank image ...

I am not as fast as you :) , so just searching in some links/files, like what you have sent.

But thanks a lot as always ;)

Greetings
Vt

Bob Phillips
09-20-2007, 04:59 AM
No, you cannot do that, but you can have a caption and an icon, like this



With Application.CommandBars("MyCtrlBar").Controls.Add(Type:=msoControlButton, ID:=2950)
.FaceId = 29
.Caption = "my Caption"
.Style = msoButtonIconAndCaption
End With

VishalkumarT
09-20-2007, 05:03 AM
Yes, Caption I have provided to the buttons.

But thank you once again for your precious help.

Gr
Vt

rory
09-20-2007, 08:00 AM
If you have the images you want stored as files, you can load those onto the commandbar controls using the .Picture (and .Mask) property:
Sub LoadPicOntoButton(strPicFile As String, ctl As CommandBarControl)
Dim oPic As stdole.IPictureDisp
Dim cbr As CommandBarControl
Set oPic = LoadPicture(strPicFile)
ctl.Picture = oPic
End Sub
Sub LoadMaskedPicOntoButton(strPicFile As String, strMaskFile As String, ctl As CommandBarControl)
Dim oPic As stdole.IPictureDisp, oMask As IPictureDisp
Dim cbr As CommandBarControl
Set oPic = LoadPicture(strPicFile)
Set oMask = LoadPicture(strMaskFile)
ctl.Picture = oPic
ctl.Mask = oMask
End Sub

VishalkumarT
09-21-2007, 01:02 AM
Hmm ...

Letttt me try :)

Thanks in advance