Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / April 2008

Tip: Looking for answers? Try searching our database.

Excel 2003 - VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Craig Brandt - 23 Apr 2008 03:51 GMT
I am trying to create a floating toolbar on the fly with dropdown menus and
also first level buttons. I cannot figure out how to assign an icon to a
button. Here is a piece of the code where I would like to assign an icon to
the Calculate button. How do I assign the ICON picture?

Help would be appreciated.
Thanks
Craig

Public Sub FltgToolbar()

'
'   Establishes a Floating Toolbar for this workbook only.

Dim RvwBar As Office.CommandBar

'   Close previous Toolbar
   On Error Resume Next
   Application.CommandBars("Returns").Delete
   With Application.CommandBars.Add
       .Name = "Returns"
       .Left = 300
       .Top = 200
       .Visible = True
       .Position = msoBarFloating
'   Download Drop Downs
       With .Controls.Add(Type:=msoControlPopup)
               .Caption = "Downloads"
               .TooltipText = "Imports Data into this WorkBook"

           With .Controls.Add(Type:=msoControlButton)
               .OnAction = "DLToday"
               .Caption = "Import Current"
           End With

           With .Controls.Add(Type:=msoControlButton)
               .OnAction = "DLPrev"
               .Caption = "Import Previous"
           End With
       End With

'   Calc Button

       With .Controls.Add(Type:=msoControlButton)
               .Caption = "Calculate"
               .OnAction = "Calculate"
               .TooltipText = "Calculates returns based on current data"
       End With
   End With
   Application.CommandBars("Returns").Controls.Add Type:=msoControlButton,
ID:=109
   Application.CommandBars("Returns").Controls.Add Type:=msoControlButton,
ID:=4
   Application.CommandBars("Returns").Controls.Add Type:=msoControlButton,
ID:=1849
   Application.CommandBars("Returns").Controls.Add Type:=msoControlButton,
ID:=436
   Application.CommandBars("Returns").Controls.Add Type:=msoControlButton,
ID:=422
End Sub
Mark Ivey - 23 Apr 2008 04:12 GMT
Here are a few examples you can look over that my shed some light on this
topic...

http://www.cpearson.com/excel/menus.htm

http://xl.barasch.com/ACu261595.htm

http://www.ozgrid.com/VBA/custom-menus.htm

Mark Ivey

> I am trying to create a floating toolbar on the fly with dropdown menus
> and
[quoted text clipped - 58 lines]
> ID:=422
> End Sub
Jim Cone - 23 Apr 2008 04:20 GMT
With .Controls.Add(Type:=msoControlButton)
           .Style = msoButtonIconAndCaption
           .Caption = "Calculate"
           .OnAction = "Calculate"
           .FaceId = 123
           .TooltipText = "Calculates returns based on current data"
   End With
Signature

Jim Cone
Portland, Oregon  USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)

"Craig Brandt"
wrote in message
I am trying to create a floating toolbar on the fly with dropdown menus and
also first level buttons. I cannot figure out how to assign an icon to a
button. Here is a piece of the code where I would like to assign an icon to
the Calculate button. How do I assign the ICON picture?
Help would be appreciated.
Thanks
Craig

Public Sub FltgToolbar()
'   Establishes a Floating Toolbar for this workbook only.

Dim RvwBar As Office.CommandBar

'   Close previous Toolbar
   On Error Resume Next
   Application.CommandBars("Returns").Delete
   With Application.CommandBars.Add
       .Name = "Returns"
       .Left = 300
       .Top = 200
       .Visible = True
       .Position = msoBarFloating
'   Download Drop Downs
       With .Controls.Add(Type:=msoControlPopup)
               .Caption = "Downloads"
               .TooltipText = "Imports Data into this WorkBook"

           With .Controls.Add(Type:=msoControlButton)
               .OnAction = "DLToday"
               .Caption = "Import Current"
           End With

           With .Controls.Add(Type:=msoControlButton)
               .OnAction = "DLPrev"
               .Caption = "Import Previous"
           End With
       End With

'   Calc Button

       With .Controls.Add(Type:=msoControlButton)
               .Caption = "Calculate"
               .OnAction = "Calculate"
               .TooltipText = "Calculates returns based on current data"
       End With
   End With
   Application.CommandBars("Returns").Controls.Add Type:=msoControlButton,
ID:=109
   Application.CommandBars("Returns").Controls.Add Type:=msoControlButton,
ID:=4
   Application.CommandBars("Returns").Controls.Add Type:=msoControlButton,
ID:=1849
   Application.CommandBars("Returns").Controls.Add Type:=msoControlButton,
ID:=436
   Application.CommandBars("Returns").Controls.Add Type:=msoControlButton,
ID:=422
End Sub

Craig Brandt - 23 Apr 2008 05:56 GMT
Thanks,

Jim - I used your solution and Mark I saved you pointers.

Thanks again,
Craig

>     With .Controls.Add(Type:=msoControlButton)
>             .Style = msoButtonIconAndCaption
[quoted text clipped - 3 lines]
>             .TooltipText = "Calculates returns based on current data"
>     End With
Klemen25 - 23 Apr 2008 07:23 GMT
Hy
Just if you need, or if someone else would later: to search for ID
numbers of excel icons this is a great help:
http://skp.mvps.org/faceid.htm

Best regards

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.