Is it possible? I'd like to make one where you can open up various
submenus, and eventually select an option that has a macro
attached....(like eg the 'all programs' menu that branches off the
'start' option on windows. SURELY that's possible!
Cheers,
Tom--
TAL27
------------------------------------------------------------------------
TAL27's Profile: www.excelforum.com/member.php...oamp;userid=30145
View this thread: www.excelforum.com/showthread...hreadid=498749Here is an example
Option Explicit
'If you put code in the appropriate workbook open event, and
'delete it in the close it will exist only for that workbook.
'Here is an example of a building a commandbar on the fly
'when you open a workbook. It adds a sub-menu to the Tools menu.
Private Sub Workbook_Open()
Dim oCb As CommandBar
Dim oCtl As CommandBarPopup
Dim oCtlBtn As CommandBarButton
Set oCb = Application.CommandBars(quot;Worksheet Menu Barquot;)
With oCb
Set oCtl = .Controls(quot;Toolsquot;).Controls.Add( _
Type:=msoControlPopup, _
temporary:=True)
oCtl.Caption = quot;myButtonquot;
With oCtl
Set oCtlBtn = .Controls.Add( _
Type:=msoControlButton, _
temporary:=True)
oCtlBtn.Caption = quot;myMacroButtonquot;
oCtlBtn.FaceId = 161
oCtlBtn.OnAction = quot;myMacroquot;
End With
With oCtl
Set oCtlBtn = .Controls.Add( _
Type:=msoControlButton, _
temporary:=True)
oCtlBtn.Caption = quot;myMacroButton2quot;
oCtlBtn.FaceId = 161
oCtlBtn.OnAction = quot;myMacro2quot;
End With
'etc.
End With
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim oCb As CommandBar
Set oCb = Application.CommandBars(quot;Worksheet Menu Barquot;)
oCb.Controls(quot;Toolsquot;).Controls(quot;myButtonquot;).Delete
End Sub
'To add this, go to the VB IDE (ALT-F11 from Excel), and in
'the explorer pane, select your workbook. Then select the
'ThisWorkbook object (it's in Microsoft Excel Objects which
'might need expanding). Double-click the ThisWorkbook and
'a code window will open up. Copy this code into there,
'changing the caption and action to suit.
'This is part of the workbook, and will only exist with the
'workbook, but will be available to anyone who opens the
'workbook.--
HTH
Bob Phillips
(remove nothere from email address if mailing direct)
quot;TAL27quot; gt; wrote in message
...
gt;
gt; Is it possible? I'd like to make one where you can open up various
gt; submenus, and eventually select an option that has a macro
gt; attached....(like eg the 'all programs' menu that branches off the
gt; 'start' option on windows. SURELY that's possible!
gt;
gt; Cheers,
gt;
gt; Tom
gt;
gt;
gt; --
gt; TAL27
gt; ------------------------------------------------------------------------
gt; TAL27's Profile:
www.excelforum.com/member.php...oamp;userid=30145
gt; View this thread: www.excelforum.com/showthread...hreadid=498749
gt;
Thanks Bob - have copied in the code you gave, but can't really see what
difference it has made. Has something appeared on the Tools menu? I
can't see a new option?
Cheers,
Tom
PS sorry about late reply - haven't been able to access internet
lately.--
TAL27
------------------------------------------------------------------------
TAL27's Profile: www.excelforum.com/member.php...oamp;userid=30145
View this thread: www.excelforum.com/showthread...hreadid=498749
- Jul 16 Mon 2007 20:38
making your own menus on excel?
close
全站熱搜
留言列表
發表留言