ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   making your own menus on excel? (https://www.excelbanter.com/excel-discussion-misc-queries/63536-making-your-own-menus-excel.html)

TAL27

making your own menus on excel?
 

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: http://www.excelforum.com/member.php...o&userid=30145
View this thread: http://www.excelforum.com/showthread...hreadid=498749


Bob Phillips

making your own menus on excel?
 
Here 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("Worksheet Menu Bar")
With oCb
Set oCtl = .Controls("Tools").Controls.Add( _
Type:=msoControlPopup, _
temporary:=True)
oCtl.Caption = "myButton"
With oCtl
Set oCtlBtn = .Controls.Add( _
Type:=msoControlButton, _
temporary:=True)
oCtlBtn.Caption = "myMacroButton"
oCtlBtn.FaceId = 161
oCtlBtn.OnAction = "myMacro"
End With
With oCtl
Set oCtlBtn = .Controls.Add( _
Type:=msoControlButton, _
temporary:=True)
oCtlBtn.Caption = "myMacroButton2"
oCtlBtn.FaceId = 161
oCtlBtn.OnAction = "myMacro2"
End With
'etc.
End With
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim oCb As CommandBar

Set oCb = Application.CommandBars("Worksheet Menu Bar")
oCb.Controls("Tools").Controls("myButton").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)

"TAL27" wrote in message
...

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:

http://www.excelforum.com/member.php...o&userid=30145
View this thread: http://www.excelforum.com/showthread...hreadid=498749




TAL27

making your own menus on excel?
 

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: http://www.excelforum.com/member.php...o&userid=30145
View this thread: http://www.excelforum.com/showthread...hreadid=498749



All times are GMT +1. The time now is 08:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com