G
Greg Lovern
I have a custom toolbar icon that looked fine in Excel 2003 but now
looks ugly in Excel 2007. We want it to work in both Excel 2007 and
Excel 2003, so I can't just make a custom Excel 2007 Ribbon tab.
I'm trying it two different ways in Excel 2007, and getting the same
results both ways:
First way:
Dim cbc As Object 'CommandBarControl
Set cbc = cb.Controls.Add(msoControlButton)
cbc.BeginGroup = True
cbc.Caption = "My Icon"
cbc.FaceId = 176
cbc.Style = msoButtonIcon
'Toolbar must be hidden while icon is replaced:
cb.Visible = False
shIcons.Shapes("16x16x256").Copy 'shIcons is a worksheet.
cbc.PasteFace
cb.Visible = True
Second Way:
(Thanks to KeepITCool's posts here)
Dim oMask As stdole.StdPicture
Dim cbc As Object 'CommandBarControl
Set cbc = cb.Controls.Add(msoControlButton)
cbc.BeginGroup = True
cbc.Caption = "My Icon"
cbc.FaceId = 176
cbc.Style = msoButtonIcon
'Toolbar must be hidden while icon is replaced:
cb.Visible = False
shIcons.Shapes("16x16x256_mask").CopyPicture xlScreen, xlBitmap
cbc.PasteFace
Set oMask = CallByName(cbc, "Picture", VbGet)
shIcons.Shapes("16x16x256").CopyPicture xlScreen, xlBitmap
cbc.PasteFace
CallByName cbc, "Mask", VbLet, oMask
cb.Visible = True
The second way looks better in Excel 2003, but both ways look very bad
in Excel 2007.
Any suggestions?
Thanks,
Greg
looks ugly in Excel 2007. We want it to work in both Excel 2007 and
Excel 2003, so I can't just make a custom Excel 2007 Ribbon tab.
I'm trying it two different ways in Excel 2007, and getting the same
results both ways:
First way:
Dim cbc As Object 'CommandBarControl
Set cbc = cb.Controls.Add(msoControlButton)
cbc.BeginGroup = True
cbc.Caption = "My Icon"
cbc.FaceId = 176
cbc.Style = msoButtonIcon
'Toolbar must be hidden while icon is replaced:
cb.Visible = False
shIcons.Shapes("16x16x256").Copy 'shIcons is a worksheet.
cbc.PasteFace
cb.Visible = True
Second Way:
(Thanks to KeepITCool's posts here)
Dim oMask As stdole.StdPicture
Dim cbc As Object 'CommandBarControl
Set cbc = cb.Controls.Add(msoControlButton)
cbc.BeginGroup = True
cbc.Caption = "My Icon"
cbc.FaceId = 176
cbc.Style = msoButtonIcon
'Toolbar must be hidden while icon is replaced:
cb.Visible = False
shIcons.Shapes("16x16x256_mask").CopyPicture xlScreen, xlBitmap
cbc.PasteFace
Set oMask = CallByName(cbc, "Picture", VbGet)
shIcons.Shapes("16x16x256").CopyPicture xlScreen, xlBitmap
cbc.PasteFace
CallByName cbc, "Mask", VbLet, oMask
cb.Visible = True
The second way looks better in Excel 2003, but both ways look very bad
in Excel 2007.
Any suggestions?
Thanks,
Greg