Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Menumaker.xls Create Macro on User Toolbar

I have a hidden workbook that comes up each time I start
the Excel 2000 program with a toolbar attached to it
called Bruce's tools. This custom toolbar contains a few
specialized shortcuts that I use on a regular basis.

Apart from this, I use a variation of J Walkenbach's
menumaker.xls in which I may have two or more open
workbooks at any given time that have customized menu
trees. If one workbook is closed, then the menu tree goes
away by the very nature of design in menumaker.xls.

I don't really wish to alter his work because I want it to
work properly in all my cases. What I want to do is to add
a button to my toolbar that would call up the Create Menu
macro in the Active Workbook. Right now if I close a
workbook containing the before_close method that deletes
the menu, then if I switch to another workbook that also
has its custom macro call "Create Menu" , then I have to
go to its worksheet labeled Menusheet and click on the
button called "Create Menu" which calls up the code listed
below. The Menusheet worksheet in the active workbook also
contains a menu tree specific to the that workbook's
needs. There may be several workbooks open at a time that
contain a sheet named Menusheet with customized menutrees
for that particular workbook.

What I want to have the toolbar item do is to take the
place of having to go to the active workbook's sheet named
Menusheet and click on the button named "Create Menu".

This macro code found in menumaker.xls I am speaking of is
listed below if you need to refer to it. I don't wish to
change that code itself because I want it to work as well
in the past as it has when I open any given workbook and
it automatically does it thing when opened. This
workaround is just a shortcut to reestablish the menu tree
for the active workbook whenever a previous workbook being
closed has also removed the customized menu tree for that
particular workbook.


Sub CreateMenu()
' This sub should be executed when the workbook is
opened.
' NOTE: There is no error handling in this subroutine

Dim MenuSheet As Worksheet
Dim MenuObject As CommandBarPopup

Dim MenuItem As Object
Dim SubMenuItem As CommandBarButton
Dim Row As Integer
Dim MenuLevel, NextLevel, PositionOrMacro, Caption,
Divider, FaceId

'''''''''''''''''''''''''''''''''''''''''''''''''' ''
' Location for menu data
Set MenuSheet = ThisWorkbook.Sheets("MenuSheet")
'''''''''''''''''''''''''''''''''''''''''''''''''' ''

' Make sure the menus aren't duplicated
Call DeleteMenu

' Initialize the row counter
Row = 2

' Add the menus, menu items and submenu items using
' data stored on MenuSheet

Do Until IsEmpty(MenuSheet.Cells(Row, 1))
With MenuSheet
MenuLevel = .Cells(Row, 1)
Caption = .Cells(Row, 2)
PositionOrMacro = .Cells(Row, 3)
Divider = .Cells(Row, 4)
FaceId = .Cells(Row, 5)
NextLevel = .Cells(Row + 1, 1)
End With

Select Case MenuLevel
Case 1 ' A Menu
' Add the top-level menu to the Worksheet
CommandBar
Set MenuObject = Application.CommandBars
(1). _
Controls.Add(Type:=msoControlPopup, _
Befo=PositionOrMacro, _
temporary:=True)
MenuObject.Caption = Caption

Case 2 ' A Menu Item
If NextLevel = 3 Then
Set MenuItem = MenuObject.Controls.Add
(Type:=msoControlPopup)
Else
Set MenuItem = MenuObject.Controls.Add
(Type:=msoControlButton)
MenuItem.OnAction = PositionOrMacro
End If
MenuItem.Caption = Caption
If FaceId < "" Then MenuItem.FaceId =
FaceId
If Divider Then MenuItem.BeginGroup = True

Case 3 ' A SubMenu Item
Set SubMenuItem = MenuItem.Controls.Add
(Type:=msoControlButton)
SubMenuItem.Caption = Caption
SubMenuItem.OnAction = PositionOrMacro
If FaceId < "" Then SubMenuItem.FaceId =
FaceId
If Divider Then SubMenuItem.BeginGroup =
True
End Select
Row = Row + 1
Loop
End Sub

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
Macro code to create a toolbar? Do what I can, but I''m only one man. Excel Discussion (Misc queries) 3 October 24th 08 12:08 AM
First Time Macro User--Stop Recording Toolbar [email protected] Excel Discussion (Misc queries) 1 November 16th 07 10:44 PM
Can I create a command box fora macro to be stored on my toolbar Barb Reinhardt New Users to Excel 0 May 15th 07 01:24 AM
Can I create a command box fora macro to be stored on my toolbar Office Junior New Users to Excel 0 May 11th 07 12:01 PM
Create dictionary of terms, create first time user site Solitaire Jane Austin New Users to Excel 1 January 19th 06 09:47 PM


All times are GMT +1. The time now is 02:19 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"