PC Review


Reply
Thread Tools Rate Thread

Add custom icon using VBA

 
 
SLW612
Guest
Posts: n/a
 
      13th Feb 2008
Hi, I have a toolbar that is stored in the personal.xls workbook and is
created each time I start Excel (2003 for xp). There are three buttons - the
first two have regular face id's, but the third I specifically designed a
button icon for. I just have no idea how to assign that icon to that macro.
I have saved the icon as a picture on sheet1 of my personal workbook (named
"calendar"), but I get an error message saying the picture is not found. I
also tried to activate the personal workbook but I kept getting more error
messages so I guess I am doing it wrong. Any help is appreciated!

Here is a snippet of my code:

c = 1
fID = 2167
Sheet1.Shapes("Calendar").Copy
For iCtr = LBound(MacNames) To UBound(MacNames)

With .Controls.Add(Type:=msoControlButton)
.OnAction = "'" & ThisWorkbook.Name & "'!" & MacNames(iCtr)
.Caption = CapNamess(iCtr)
.Style = msoButtonIcon
If Not c = 3 Then
.FaceId = fID
Else
.PasteFace
End If
.TooltipText = TipText(iCtr)
End With
fID = fID - 2100
c = c + 1
Next iCtr
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      13th Feb 2008
Here's one that I saved. Maybe you can pick the pieces out.

Did you create a worksheet with 5 pictures named pic1, pic2, pic3, pic4, pic5 on
it?

For i = LBound(mac_names) To UBound(mac_names)
Worksheets("PictSheetNameHere").Pictures("pic" & i + 1).Copy
With .Controls.Add(Type:=msoControlButton)
.OnAction = "'" & ThisWorkbook.Name & "'!" & mac_names(i)
.Caption = cap_names(i)
.Style = msoButtonIconAndCaption
.PasteFace
.TooltipText = tip_text(i)
End With
Next i

SLW612 wrote:
>
> Hi, I have a toolbar that is stored in the personal.xls workbook and is
> created each time I start Excel (2003 for xp). There are three buttons - the
> first two have regular face id's, but the third I specifically designed a
> button icon for. I just have no idea how to assign that icon to that macro.
> I have saved the icon as a picture on sheet1 of my personal workbook (named
> "calendar"), but I get an error message saying the picture is not found. I
> also tried to activate the personal workbook but I kept getting more error
> messages so I guess I am doing it wrong. Any help is appreciated!
>
> Here is a snippet of my code:
>
> c = 1
> fID = 2167
> Sheet1.Shapes("Calendar").Copy
> For iCtr = LBound(MacNames) To UBound(MacNames)
>
> With .Controls.Add(Type:=msoControlButton)
> .OnAction = "'" & ThisWorkbook.Name & "'!" & MacNames(iCtr)
> .Caption = CapNamess(iCtr)
> .Style = msoButtonIcon
> If Not c = 3 Then
> .FaceId = fID
> Else
> .PasteFace
> End If
> .TooltipText = TipText(iCtr)
> End With
> fID = fID - 2100
> c = c + 1
> Next iCtr


--

Dave Peterson
 
Reply With Quote
 
SLW612
Guest
Posts: n/a
 
      13th Feb 2008
Well ... it didn't quite work ...

I'm now getting the error message:

Run-time error '1004':
Method 'Worksheets' of object '_Global' failed

I am using face id's for two buttons and just want the one button with a
custom designed icon. 3 buttons total.

"Dave Peterson" wrote:

> Here's one that I saved. Maybe you can pick the pieces out.
>
> Did you create a worksheet with 5 pictures named pic1, pic2, pic3, pic4, pic5 on
> it?
>
> For i = LBound(mac_names) To UBound(mac_names)
> Worksheets("PictSheetNameHere").Pictures("pic" & i + 1).Copy
> With .Controls.Add(Type:=msoControlButton)
> .OnAction = "'" & ThisWorkbook.Name & "'!" & mac_names(i)
> .Caption = cap_names(i)
> .Style = msoButtonIconAndCaption
> .PasteFace
> .TooltipText = tip_text(i)
> End With
> Next i
>
> SLW612 wrote:
> >
> > Hi, I have a toolbar that is stored in the personal.xls workbook and is
> > created each time I start Excel (2003 for xp). There are three buttons - the
> > first two have regular face id's, but the third I specifically designed a
> > button icon for. I just have no idea how to assign that icon to that macro.
> > I have saved the icon as a picture on sheet1 of my personal workbook (named
> > "calendar"), but I get an error message saying the picture is not found. I
> > also tried to activate the personal workbook but I kept getting more error
> > messages so I guess I am doing it wrong. Any help is appreciated!
> >
> > Here is a snippet of my code:
> >
> > c = 1
> > fID = 2167
> > Sheet1.Shapes("Calendar").Copy
> > For iCtr = LBound(MacNames) To UBound(MacNames)
> >
> > With .Controls.Add(Type:=msoControlButton)
> > .OnAction = "'" & ThisWorkbook.Name & "'!" & MacNames(iCtr)
> > .Caption = CapNamess(iCtr)
> > .Style = msoButtonIcon
> > If Not c = 3 Then
> > .FaceId = fID
> > Else
> > .PasteFace
> > End If
> > .TooltipText = TipText(iCtr)
> > End With
> > fID = fID - 2100
> > c = c + 1
> > Next iCtr

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      13th Feb 2008
When you get errors, you'll want to post the code and indicate the line that
caused the error.

But maybe this will help.

> > > If Not c = 3 Then
> > > .FaceId = fID
> > > Else

worksheets("somesheet").Pictures("somepic").copy
> > > .PasteFace
> > > End If



SLW612 wrote:
>
> Well ... it didn't quite work ...
>
> I'm now getting the error message:
>
> Run-time error '1004':
> Method 'Worksheets' of object '_Global' failed
>
> I am using face id's for two buttons and just want the one button with a
> custom designed icon. 3 buttons total.
>
> "Dave Peterson" wrote:
>
> > Here's one that I saved. Maybe you can pick the pieces out.
> >
> > Did you create a worksheet with 5 pictures named pic1, pic2, pic3, pic4, pic5 on
> > it?
> >
> > For i = LBound(mac_names) To UBound(mac_names)
> > Worksheets("PictSheetNameHere").Pictures("pic" & i + 1).Copy
> > With .Controls.Add(Type:=msoControlButton)
> > .OnAction = "'" & ThisWorkbook.Name & "'!" & mac_names(i)
> > .Caption = cap_names(i)
> > .Style = msoButtonIconAndCaption
> > .PasteFace
> > .TooltipText = tip_text(i)
> > End With
> > Next i
> >
> > SLW612 wrote:
> > >
> > > Hi, I have a toolbar that is stored in the personal.xls workbook and is
> > > created each time I start Excel (2003 for xp). There are three buttons - the
> > > first two have regular face id's, but the third I specifically designed a
> > > button icon for. I just have no idea how to assign that icon to that macro.
> > > I have saved the icon as a picture on sheet1 of my personal workbook (named
> > > "calendar"), but I get an error message saying the picture is not found. I
> > > also tried to activate the personal workbook but I kept getting more error
> > > messages so I guess I am doing it wrong. Any help is appreciated!
> > >
> > > Here is a snippet of my code:
> > >
> > > c = 1
> > > fID = 2167
> > > Sheet1.Shapes("Calendar").Copy
> > > For iCtr = LBound(MacNames) To UBound(MacNames)
> > >
> > > With .Controls.Add(Type:=msoControlButton)
> > > .OnAction = "'" & ThisWorkbook.Name & "'!" & MacNames(iCtr)
> > > .Caption = CapNamess(iCtr)
> > > .Style = msoButtonIcon
> > > If Not c = 3 Then
> > > .FaceId = fID
> > > Else
> > > .PasteFace
> > > End If
> > > .TooltipText = TipText(iCtr)
> > > End With
> > > fID = fID - 2100
> > > c = c + 1
> > > Next iCtr

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is this a bug: Intead of custom icon location, custom web pageshortcuts in Favoroites > Properties > Change icon... > always show %SystemRoot%\system32\SHELL32.dll c627627 Windows XP Help 1 26th Mar 2011 08:35 PM
Creating custom Message Form. Issue with custom Icon Abhishek Tripathi Microsoft Outlook Form Programming 0 1st Dec 2008 11:39 AM
change envelop icon with custom icon in outlook addin ajaykumarrudra Windows XP 0 24th Jul 2008 05:11 AM
Custom icon superseded by tracking icon =?Utf-8?B?VmF1Z2hhbg==?= Microsoft Outlook Form Programming 4 24th Feb 2006 12:47 PM
Web Site I Know Has A Custom Icon Does Not Show Icon in Favorites Terngu Nomishan Windows XP Internet Explorer 1 3rd Aug 2004 06:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:41 PM.