PC Review


Reply
Thread Tools Rate Thread

Add File menu to custom toolbar

 
 
michael.beckinsale
Guest
Posts: n/a
 
      17th Dec 2009
Hi All,

I am trying to add the 'File" menu and "Window" menu of the Standard
Toolbar to a custom toolbar but failing miserably!

I think it should look something like:

Sub AddMenuTitles()
Application.CommandBars("MyCustomMenu").Controls.Add("File)
Application.CommandBars("MyCustomMenu").Controls.Add("Window")
End Sub

Can anybody help please

Regards

Michael
 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      17th Dec 2009
Sub test()
AddMenuTitles True ' or false to delete
End Sub

Sub AddMenuTitles(bAdd As Boolean)
Dim cbr As CommandBar
Dim cbP As CommandBarPopup

On Error Resume Next
CommandBars("TestBar").Delete
On Error GoTo 0
If Not bAdd Then Exit Sub

' might want to include other arg's in .Add()
Set cbr = CommandBars.Add("TestBar", temporary:=True)

Set cbP = cbr.Controls.Add(ID:=30002) ' file
Set cbP = cbr.Controls.Add(ID:=30003) ' edit

cbr.Visible = True

End Sub

Regards,
Peter T


"michael.beckinsale" <(E-Mail Removed)> wrote in message
news:a4f854df-5a02-42b6-a09f-(E-Mail Removed)...
> Hi All,
>
> I am trying to add the 'File" menu and "Window" menu of the Standard
> Toolbar to a custom toolbar but failing miserably!
>
> I think it should look something like:
>
> Sub AddMenuTitles()
> Application.CommandBars("MyCustomMenu").Controls.Add("File)
> Application.CommandBars("MyCustomMenu").Controls.Add("Window")
> End Sub
>
> Can anybody help please
>
> Regards
>
> Michael



 
Reply With Quote
 
michael.beckinsale
Guest
Posts: n/a
 
      17th Dec 2009
Hi Peter,

Many thanks, nice piece of code.

A couple of questions if you dont mind:

1. Where did you get the ID's from?
2. How can l 'anchor' the custom toolbar at sat 'top left' bearing in
mind 3. below?
3. My intention is to delete the users existing Excel menu when
This.Workbook is active, present the user with my custom toolbar, and
then restore the users existing Excel menu when This.Workbook is
inactive. I think l know how to do this using the the
Workbook.Activate & Workbook.Deactivate events but l would br grateful
for any observations / pointers as menu manipulation is not something
l have coded much!

Regards

Michael

 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      17th Dec 2009
(untested)
dim ctr as commandbarcontrol
for each ctr in CommandBars("Worksheet Menu Bar").controls
debug.? ctr.id, ctr.caption
next

The ID of Built-in controls is never 1, You can add copies of built-in
controls to your bar simply as shown.

Following toggles the main menu bar and docks the custom bar to top

Sub test()
AddMenuTitles True ' or false to delete
End Sub

Sub AddMenuTitles(bAdd As Boolean)
Dim cbr As CommandBar
Dim cbP As CommandBarPopup

CommandBars("Worksheet Menu Bar").Enabled = Not bAdd

On Error Resume Next
CommandBars("TestBar").Delete
On Error GoTo 0

If Not bAdd Then Exit Sub

Set cbr = CommandBars.Add("TestBar", Position:=msoBarTop,
temporary:=True)

Set cbP = cbr.Controls.Add(ID:=30002) ' file
Set cbP = cbr.Controls.Add(ID:=30003) ' edit

cbr.Visible = True

End Sub


Always a bit risky messing with user's settings, I tend not to like apps
that do that. But if needs dictate, call 'AddMenuTitles False' liberally in
all relevant thisworkbook events when your wb is no longer active, eg
beforeclose, deavtivate etc.

Regards,
Peter T



"michael.beckinsale" <(E-Mail Removed)> wrote in message
news:08d4017c-0262-4b6b-b82a-(E-Mail Removed)...
> Hi Peter,
>
> Many thanks, nice piece of code.
>
> A couple of questions if you dont mind:
>
> 1. Where did you get the ID's from?
> 2. How can l 'anchor' the custom toolbar at sat 'top left' bearing in
> mind 3. below?
> 3. My intention is to delete the users existing Excel menu when
> This.Workbook is active, present the user with my custom toolbar, and
> then restore the users existing Excel menu when This.Workbook is
> inactive. I think l know how to do this using the the
> Workbook.Activate & Workbook.Deactivate events but l would br grateful
> for any observations / pointers as menu manipulation is not something
> l have coded much!
>
> Regards
>
> Michael
>



 
Reply With Quote
 
michael.beckinsale
Guest
Posts: n/a
 
      17th Dec 2009
Hi Peter,

Again thanks very much.

I agree with you re messing about with the users menu settings, hence
my lack of knowledge as l have infrequently coded the menu, however in
this instance the sponsor has requested a 'clean' look!

Regards

Michael

 
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
Custom Toolbar/Menu for UserForm =?Utf-8?B?bWlrZWc3MTA=?= Microsoft Excel Programming 3 20th Jun 2007 10:26 AM
Custom Menu activates Web Toolbar =?Utf-8?B?QkVFSkFZ?= Microsoft Excel Discussion 1 22nd Sep 2006 04:29 PM
VBA - Disappearing custom menu and custom toolbar Peter Microsoft Excel Programming 2 2nd Dec 2004 06:09 PM
Updating Custom Toolbar/Menu belfourisbetter Microsoft Excel Misc 4 4th May 2004 02:35 PM
Custom shortcuts in custom toolbar/menu Anon Microsoft Outlook 0 15th Oct 2003 11:02 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:43 PM.