Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Excel 2003 toolbar with custom image

Hi,
Is it possible to use a custom image for excel toolbar? I mean using
external picture such as .png, .img...etc. The toolbar was created in xla
format using vba.

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Excel 2003 toolbar with custom image

You can certainly use your 16x16 picture for the icon property of a button,
but nothing larger than that on a commandbar.

It Excel 2007 you can use 'Gallery' for your own pictures in your
customized Ribbon.

Regards,
Peter T

"Westman" wrote in message
...
Hi,
Is it possible to use a custom image for excel toolbar? I mean using
external picture such as .png, .img...etc. The toolbar was created in xla
format using vba.

Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Excel 2003 toolbar with custom image

Thanks for the reply.

What is the best way to do that? How to use external picture in my toolbar?



"Peter T" wrote:

You can certainly use your 16x16 picture for the icon property of a button,
but nothing larger than that on a commandbar.

It Excel 2007 you can use 'Gallery' for your own pictures in your
customized Ribbon.

Regards,
Peter T

"Westman" wrote in message
...
Hi,
Is it possible to use a custom image for excel toolbar? I mean using
external picture such as .png, .img...etc. The toolbar was created in xla
format using vba.

Thanks.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Excel 2003 toolbar with custom image

Simplest way would be first to "Insert" the picture onto a sheet, then
CopyPicture and PasteFace. Adapt the following to your needs -

Sub test()
Dim sPic As String, sPath As String
Dim cbr As CommandBar
Dim cbt As CommandBarButton

On Error Resume Next
' delete the old bar if it exists
CommandBars("TestBar").Delete
On Error GoTo 0

sPath = "C:\Documents and Settings\Owner\My Documents\My Pictures\"

Set cbr = CommandBars.Add("TestBar", temporary:=True)
Set cbt = cbr.Controls.Add(msoControlButton)

sPic = "myPic.bmp"

If GetAndCopyPic(sPath, sPic) Then
cbt.PasteFace
Else
' what to do if failed to get the picture
MsgBox "failed to copy " & sPic
End If

cbt.OnAction = "myMacro"
cbt.Visible = True

cbr.Visible = True

End Sub

Function GetAndCopyPic(sPath As String, sPic As String) As Boolean
Dim sName As String
Dim ws As Worksheet
Dim pic As Picture

On Error GoTo errH
Set ws = ThisWorkbook.Worksheets("Sheet1")
sName = Left$(sPic, InStrRev(sPic, ".") - 1)

On Error Resume Next
Set pic = ws.Pictures(sName)
On Error GoTo errH

If pic Is Nothing Then
Set pic = ws.Pictures.Insert(sPath & sPic)
pic.Name = sName
End If

pic.CopyPicture
GetAndCopyPic = True

Exit Function

errH:
Debug.Print Err.Description
''' uncoment for testing
'stop
'resume nextion
End Function


Regards,
Peter T

"Westman" wrote in message
...
Thanks for the reply.

What is the best way to do that? How to use external picture in my
toolbar?



"Peter T" wrote:

You can certainly use your 16x16 picture for the icon property of a
button,
but nothing larger than that on a commandbar.

It Excel 2007 you can use 'Gallery' for your own pictures in your
customized Ribbon.

Regards,
Peter T

"Westman" wrote in message
...
Hi,
Is it possible to use a custom image for excel toolbar? I mean using
external picture such as .png, .img...etc. The toolbar was created in
xla
format using vba.

Thanks.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Excel 2003 toolbar with custom image

Thanks, it worked.

"Peter T" wrote:

Simplest way would be first to "Insert" the picture onto a sheet, then
CopyPicture and PasteFace. Adapt the following to your needs -

Sub test()
Dim sPic As String, sPath As String
Dim cbr As CommandBar
Dim cbt As CommandBarButton

On Error Resume Next
' delete the old bar if it exists
CommandBars("TestBar").Delete
On Error GoTo 0

sPath = "C:\Documents and Settings\Owner\My Documents\My Pictures\"

Set cbr = CommandBars.Add("TestBar", temporary:=True)
Set cbt = cbr.Controls.Add(msoControlButton)

sPic = "myPic.bmp"

If GetAndCopyPic(sPath, sPic) Then
cbt.PasteFace
Else
' what to do if failed to get the picture
MsgBox "failed to copy " & sPic
End If

cbt.OnAction = "myMacro"
cbt.Visible = True

cbr.Visible = True

End Sub

Function GetAndCopyPic(sPath As String, sPic As String) As Boolean
Dim sName As String
Dim ws As Worksheet
Dim pic As Picture

On Error GoTo errH
Set ws = ThisWorkbook.Worksheets("Sheet1")
sName = Left$(sPic, InStrRev(sPic, ".") - 1)

On Error Resume Next
Set pic = ws.Pictures(sName)
On Error GoTo errH

If pic Is Nothing Then
Set pic = ws.Pictures.Insert(sPath & sPic)
pic.Name = sName
End If

pic.CopyPicture
GetAndCopyPic = True

Exit Function

errH:
Debug.Print Err.Description
''' uncoment for testing
'stop
'resume nextion
End Function


Regards,
Peter T

"Westman" wrote in message
...
Thanks for the reply.

What is the best way to do that? How to use external picture in my
toolbar?



"Peter T" wrote:

You can certainly use your 16x16 picture for the icon property of a
button,
but nothing larger than that on a commandbar.

It Excel 2007 you can use 'Gallery' for your own pictures in your
customized Ribbon.

Regards,
Peter T

"Westman" wrote in message
...
Hi,
Is it possible to use a custom image for excel toolbar? I mean using
external picture such as .png, .img...etc. The toolbar was created in
xla
format using vba.

Thanks.






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help w using custom image for custom toolbar in Excel 2007 vbaexperimenter Excel Programming 10 June 23rd 08 06:05 PM
How to increase size of image in button (msocontrolbutton) of custom toolbar of Excel padam Excel Discussion (Misc queries) 0 August 11th 06 07:18 PM
How to increase size of image in button (msocontrolbutton) of custom toolbar of Excel 2000 [email protected] Excel Programming 0 August 8th 06 06:33 AM
how to increase size of button's image of custom toolbar of Excel Padam Excel Programming 0 August 7th 06 03:39 PM
Load image from directory for custom toolbar of Excel 2000 Padam Excel Worksheet Functions 0 August 5th 06 06:33 PM


All times are GMT +1. The time now is 03:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"