Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default How to add a button in Excel tool bar in order to run my macro?

Thank you for your help!

"Patrick Molloy" ...
Option Explicit


Sub AddMenu()

Dim ctrlMain As CommandBarPopup
Dim ctrlItem As CommandBarControl
Dim ctrlSubItem As CommandBarButton

KillMenu

Set ctrlMain = CommandBars("Worksheet Menu Bar").Controls.Add _
(Type:=msoControlPopup, _
temporary:=True)

With ctrlMain
.Caption = "M&y Menus"

Set ctrlItem = .Controls.Add(Type:=msoControlButton)
With ctrlItem
.Caption = "Proc &1"
.OnAction = "mnuProc1"
End With
Set ctrlItem = .Controls.Add(Type:=msoControlPopup)
With ctrlItem

.Caption = "Proc &2"
.BeginGroup = True

Set ctrlSubItem = .Controls.Add(Type:=msoControlButton)
With ctrlSubItem
.Caption = "Sub 2&a"
.OnAction = "mnuProc2subA"
End With
Set ctrlSubItem = .Controls.Add(Type:=msoControlButton)
With ctrlSubItem
.Caption = "sub 2&b"
.OnAction = "mnuProc2SubB"
End With
End With
Set ctrlItem = .Controls.Add(Type:=msoControlButton)
With ctrlItem
.Caption = "Proc &3"
.BeginGroup = True
.OnAction = "mnuProc3"
End With
End With

With CommandBars.Add("MyPopup", msoBarPopup, , True)
With .Controls.Add(msoControlButton)
.Caption = "A"
.FaceId = 3825
End With
With .Controls.Add(msoControlButton)
.Caption = "B"
.FaceId = 3826

End With

End With

End Sub
Sub KillMenu()
Dim cmdbar As CommandBar
On Error Resume Next
Set cmdbar = CommandBars("Worksheet Menu Bar")
cmdbar.Controls("My Menus").Delete
CommandBars("MyPopup").Delete
On Error GoTo 0

End Sub
Private Sub mnuProc1()
MsgBox "proc1"
End Sub
Private Sub mnuProc2subA()
MsgBox "proc2_A"
End Sub
Private Sub mnuProc2subB()
MsgBox "proc2_B"
End Sub
Private Sub mnuProc3()
MsgBox "proc3"
End Sub



"Terry" wrote:

Hi,
I write a macro in Excel. In order to run my macro conveniently, I
want
to add a button in Excel tool bar. Would you tell me how to do? Thank you
very much!





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
Excel 2002: How to insert an Auto Fit Width button at the tool bar Mr. Low Excel Discussion (Misc queries) 2 July 4th 09 10:19 AM
Tool to automatically install a macro + button on 200+ instances ofexcel? [email protected] Excel Worksheet Functions 0 January 30th 09 11:49 PM
Add a formated date button for Excel 2002 tool bar Mr. Low Excel Discussion (Misc queries) 1 October 30th 06 04:12 PM
Restore Excel program Miminize button on Top tool bar Craneman Excel Discussion (Misc queries) 1 January 25th 06 06:41 PM
Excel's draw tool to create a Macro Button JulieD Excel Programming 1 August 5th 04 06:26 PM


All times are GMT +1. The time now is 12:14 AM.

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

About Us

"It's about Microsoft Excel"