Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Menu Items????

Status
Not open for further replies.

ribhead

Technical User
Jun 2, 2003
384
US
I am trying to create a menu item with a macro assigned to it that will only be used for one worksheet so everytime the user opens this up it will be created and when he/she exits I will reset the menubars using MenuBars(xlworksheet).Reset This is probably easy to do but all I have is a manual from 1992 and I'm not comprehending what the manual is saying. Below is what was recorded.

Application.CommandBars("Worksheet Menu Bar").Controls.Add Type:= _
msoControlPopup, Before:=10

I may not be very smart but I'm sure wirey!!!!
 
Here is an example for you to play with:
Code:
  'Create command bar
    Set tsBar = CommandBars.Add(Name:="Timesheet")
    
  'Set command bar properties
    With tsBar
      .Position = msoBarFloating
      .Top = 130
      .Left = 165
      .Visible = True
    End With
    
   'Add controls  
   'Specific Macro button
    Set SpecificMacroBtn = tsBar.Controls.Add(Type:=msoControlButton)
    With SpecificMacroBtn
      .Style = msoButtonCaption
      .Caption = "Specific macro..."
      .OnAction = "Run_Specific_Macro"
    End With

The important line is the .OnAction line which specifies which macro to run. Run_Specific_Macro is a routine defined in one of my modules.



Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
I'm getting confused here sorry, I typed this in and it does work however all I want to do is to place the menu item to the left of "Help". I also want to delete this out
during Auto_Close.

sub Auto_Open
'This is where I want to create a new menu item with a Macro
assigned to it.

sub Auto_Close
'This is where I want to get rid of the new menu item so it's not visible on any other Excel sheet.

MenuBars(xlworksheet).Reset

I do appreciate the help. No Really I'm just very very green.



I may not be very smart but I'm sure wirey!!!!
 
I used pretty much what you gave me, I did modidfy it a bit though Thanks a bunch.
Auto_Open
'Create command bar
Set tsBar = CommandBars.Add(Name:="MainMenuBar")

'Set command bar properties
With tsBar
.Position = msoBarTop

.Visible = True
End With

'Add controls
'Specific Macro button
Set SpecificMacroBtn = tsBar.Controls.Add(Type:=msoControlButton)
With SpecificMacroBtn
.Style = msoButtonCaption
.Caption = "&MainMenu"
.OnAction = "mainmenu"
End With. Thanks a bunch.

Auto_Close
Toolbars("MainMenuBar").Delete

I may not be very smart but I'm sure wirey!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top