Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Adding menu item to Tools

I'd like to add an item to the Tools menu when I open a spreadsheet and then
delete it before the workbook closes. I've tried adding this code to the
Workbook Open event.

Private Sub Workbook_Open()
CommandBars("Worksheet men
bar").Controls("Tools").Controls.Add(Type:=msoCont rolButton).Caption="MyMenu"
End Sub

When I open the spreadsheet, I get an error 91: Object Variable or With
block variable not set.

This same codes works if I include it in the code I have for a userform I've
defined to take inputs from the user.

Ideas?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Adding menu item to Tools

Try
application.commandbars("worksheet.....



Kent McPherson wrote:

I'd like to add an item to the Tools menu when I open a spreadsheet and then
delete it before the workbook closes. I've tried adding this code to the
Workbook Open event.

Private Sub Workbook_Open()
CommandBars("Worksheet men
bar").Controls("Tools").Controls.Add(Type:=msoCont rolButton).Caption="MyMenu"
End Sub

When I open the spreadsheet, I get an error 91: Object Variable or With
block variable not set.

This same codes works if I include it in the code I have for a userform I've
defined to take inputs from the user.

Ideas?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Adding menu item to Tools

Thanks. That worked!

I then tried making a group break on the Tools menu with this command added
to my subroutine below after I created the menu item.

CommandBars("Worksheet men
bar").Controls("Tools").Controls("MyMenu").BeginGr oup = True

When I execute the delete command, it doesn't remove the item from Tools
menu anymore. It works fine without the group but not with it. Do I have
to remove the group first somehow?


"Dave Peterson" wrote in message
...
Try
application.commandbars("worksheet.....



Kent McPherson wrote:

I'd like to add an item to the Tools menu when I open a spreadsheet and
then
delete it before the workbook closes. I've tried adding this code to the
Workbook Open event.

Private Sub Workbook_Open()
CommandBars("Worksheet men
bar").Controls("Tools").Controls.Add(Type:=msoCont rolButton).Caption="MyMenu"
End Sub

When I open the spreadsheet, I get an error 91: Object Variable or With
block variable not set.

This same codes works if I include it in the code I have for a userform
I've
defined to take inputs from the user.

Ideas?


--

Dave Peterson



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Adding menu item to Tools

This worked ok for me:

Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)

With Application.CommandBars("Worksheet menu bar").Controls("Tools")
On Error Resume Next
.Controls("MyMenu").Delete
On Error GoTo 0
End With

End Sub
Private Sub Workbook_Open()

Dim myCtrl As CommandBarControl

With Application.CommandBars("Worksheet menu bar").Controls("Tools")
On Error Resume Next
.Controls("MyMenu").Delete
On Error GoTo 0
Set myCtrl = .Controls.Add(Type:=msoControlButton, temporary:=True)
End With

With myCtrl
.Caption = "MyMenu"
.BeginGroup = True
End With

End Sub


Kent McPherson wrote:

Thanks. That worked!

I then tried making a group break on the Tools menu with this command added
to my subroutine below after I created the menu item.

CommandBars("Worksheet men
bar").Controls("Tools").Controls("MyMenu").BeginGr oup = True

When I execute the delete command, it doesn't remove the item from Tools
menu anymore. It works fine without the group but not with it. Do I have
to remove the group first somehow?

"Dave Peterson" wrote in message
...
Try
application.commandbars("worksheet.....



Kent McPherson wrote:

I'd like to add an item to the Tools menu when I open a spreadsheet and
then
delete it before the workbook closes. I've tried adding this code to the
Workbook Open event.

Private Sub Workbook_Open()
CommandBars("Worksheet men
bar").Controls("Tools").Controls.Add(Type:=msoCont rolButton).Caption="MyMenu"
End Sub

When I open the spreadsheet, I get an error 91: Object Variable or With
block variable not set.

This same codes works if I include it in the code I have for a userform
I've
defined to take inputs from the user.

Ideas?


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Adding menu item to Tools

Might just be a copy and paste error but you did not specify the menu bar
correctly...

Private Sub Tada()
Application.CommandBars("Worksheet Menu
Bar").Controls("Tools").Controls.Add(Type:=msoCont rolButton).Caption =
"MyMenu"
End Sub

--
HTH...

Jim Thomlinson


"Kent McPherson" wrote:

I'd like to add an item to the Tools menu when I open a spreadsheet and then
delete it before the workbook closes. I've tried adding this code to the
Workbook Open event.

Private Sub Workbook_Open()
CommandBars("Worksheet men
bar").Controls("Tools").Controls.Add(Type:=msoCont rolButton).Caption="MyMenu"
End Sub

When I open the spreadsheet, I get an error 91: Object Variable or With
block variable not set.

This same codes works if I include it in the code I have for a userform I've
defined to take inputs from the user.

Ideas?





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
No Data Analysis item in Excel Tools menu. Now what? ainoni Excel Worksheet Functions 4 September 23rd 08 07:44 PM
Adding a menu item to Excel Uzi Barzilai Excel Discussion (Misc queries) 1 January 14th 08 10:25 AM
Adding Separator Menu Item - Excel 2003 Desi Excel Programming 2 June 9th 05 10:21 AM
Adding a Menu Item into a sheet as a button [email protected] Excel Programming 3 March 23rd 05 06:37 PM
Adding a menu item right click menu when clicking on a single. Andoni[_28_] Excel Programming 0 September 2nd 04 10:23 PM


All times are GMT +1. The time now is 01:52 PM.

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"