PC Review


Reply
Thread Tools Rate Thread

Commandbar menu, worksheet modules and workbook module.

 
 
Dave
Guest
Posts: n/a
 
      30th Jan 2007
Hi all,

I have a addin which sets up an option on the main menu bar named
'Toolz' - the code is below... this works ok. I also have similar code
in each worksheet to add a menu item relevant to that worksheet -
under the 'Toolz' option.

My aim was to activate and deactivate a menu option when the user
flicked through different workbooks using the same instance of Excel.

Here is the code I use in the addin...

Set myMnu = CommandBars("Worksheet menu bar").Controls. _
Add(Type:=msoControlPopup)
With myMnu
.Caption = "Toolz"
End With

However, when I use the following code within ThisWorkBook...

Set newSub = CommandBars("Worksheet menu bar") _
.Controls("Toolz")
With newSub
.Controls.Add(Type:=msoControlPopup).Caption = "St: Incidents"
End With

I get 'Run time error 91: Object variable or With variable not set'.

Now I've condensed the code, but whichever way I try and duplicate
what I've done in the sheet modules - I cannot get anything like it to
work in the ThisWorkBook module.

I know there is a subtle difference between sheet modules and the
workbook module. Can someone please explain why the exect same code
will work in a sheet module but not in the workbook module?

Thanks,
Dave

 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      30th Jan 2007
Dave,
You must prefix CommandBars with Application. when referring
to them in class modules. It is good practice to do that no matter
what type of module your code is in.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"Dave" <(E-Mail Removed)>
wrote in message
Hi all,

I have a addin which sets up an option on the main menu bar named
'Toolz' - the code is below... this works ok. I also have similar code
in each worksheet to add a menu item relevant to that worksheet -
under the 'Toolz' option.

My aim was to activate and deactivate a menu option when the user
flicked through different workbooks using the same instance of Excel.

Here is the code I use in the addin...

Set myMnu = CommandBars("Worksheet menu bar").Controls. _
Add(Type:=msoControlPopup)
With myMnu
.Caption = "Toolz"
End With

However, when I use the following code within ThisWorkBook...

Set newSub = CommandBars("Worksheet menu bar") _
.Controls("Toolz")
With newSub
.Controls.Add(Type:=msoControlPopup).Caption = "St: Incidents"
End With

I get 'Run time error 91: Object variable or With variable not set'.
Now I've condensed the code, but whichever way I try and duplicate
what I've done in the sheet modules - I cannot get anything like it to
work in the ThisWorkBook module.
I know there is a subtle difference between sheet modules and the
workbook module. Can someone please explain why the exect same code
will work in a sheet module but not in the workbook module?
Thanks,
Dave

 
Reply With Quote
 
Dave
Guest
Posts: n/a
 
      30th Jan 2007
On Tue, 30 Jan 2007 09:38:28 -0800, "Jim Cone"
<(E-Mail Removed)> wrote:

Thanks for that Jim, it worked fine.

Dave

>Dave,
>You must prefix CommandBars with Application. when referring
>to them in class modules. It is good practice to do that no matter
>what type of module your code is in.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use a different worksheet in a different workbook drop down menu swain.s@blueyonder.co uk Microsoft Excel Misc 1 20th Jul 2008 07:07 PM
Disable Menu (CommandBar) if not workbook is opened LuisE Microsoft Excel Programming 5 27th Dec 2007 02:11 PM
Run worksheet module code from workbook module? keithb Microsoft Excel Programming 1 14th Aug 2005 04:04 AM
re: Automatically Delete WorkBook 2 modules by using Workbook 1 module =?Utf-8?B?ZGRpaWNj?= Microsoft Excel Programming 5 27th Jul 2005 12:53 PM
identify 'save as' of the commandbar 'worksheet menu bar' Manfred Microsoft Excel Programming 2 31st Aug 2004 01:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:03 PM.