PC Review


Reply
Thread Tools Rate Thread

Delete specific menu item from custom menu

 
 
Tim
Guest
Posts: n/a
 
      10th Mar 2008
I am creating a new menu called STI to be used by future add-ins. Within
that menu, I added a menu item(msControlButton), Format Aging Report, to run
a macro. How do I delete Format Aging Report without deleting STI menu?

Sub AddMenus()

Dim cbMainMenuBar As CommandBar
Dim HelpMenuIndex As Integer
Dim cbcSTIMenu As CommandBarControl

'Would like to try to delete "Format Aging Report" here instead of current
code
On Error Resume Next
Application.CommandBars("Worksheet Menu Bar").Controls("&STI").Delete
On Error GoTo 0

Set cbMainMenuBar = Application.CommandBars("Worksheet Menu Bar")

HelpMenuIndex = cbMainMenuBar.Controls("Help").Index

Set cbcSTIMenu = cbMainMenuBar.Controls.Add(Type:=msoControlPopup,
Before:=HelpMenuIndex)

cbcSTIMenu.Caption = "&STI"

With cbcSTIMenu.Controls.Add(Type:=msoControlButton)
.Caption = "Format Aging Report"
.OnAction = "AgingReportFormat"
End With

End Sub
 
Reply With Quote
 
 
 
 
DomThePom
Guest
Posts: n/a
 
      10th Mar 2008
look at delete method od commandbarcontrol object

"Tim" wrote:

> I am creating a new menu called STI to be used by future add-ins. Within
> that menu, I added a menu item(msControlButton), Format Aging Report, to run
> a macro. How do I delete Format Aging Report without deleting STI menu?
>
> Sub AddMenus()
>
> Dim cbMainMenuBar As CommandBar
> Dim HelpMenuIndex As Integer
> Dim cbcSTIMenu As CommandBarControl
>
> 'Would like to try to delete "Format Aging Report" here instead of current
> code
> On Error Resume Next
> Application.CommandBars("Worksheet Menu Bar").Controls("&STI").Delete
> On Error GoTo 0
>
> Set cbMainMenuBar = Application.CommandBars("Worksheet Menu Bar")
>
> HelpMenuIndex = cbMainMenuBar.Controls("Help").Index
>
> Set cbcSTIMenu = cbMainMenuBar.Controls.Add(Type:=msoControlPopup,
> Before:=HelpMenuIndex)
>
> cbcSTIMenu.Caption = "&STI"
>
> With cbcSTIMenu.Controls.Add(Type:=msoControlButton)
> .Caption = "Format Aging Report"
> .OnAction = "AgingReportFormat"
> End With
>
> End Sub

 
Reply With Quote
 
Tim
Guest
Posts: n/a
 
      11th Mar 2008
Thank you Dom, here is what I came up with.
(Any suggestions on error handling or formatting welcomed)

Dim cbMainMenuBar As CommandBar
Dim HelpMenuIndex As Integer
Dim cbcSTIMenu As CommandBarControl
Dim cbcAgingReport As CommandBarControl

Set cbMainMenuBar = Application.CommandBars("Worksheet Menu Bar")
Set cbcSTIMenu = cbMainMenuBar.FindControl(Type:=msoControlPopup,
Tag:="STI")

On Error Resume Next
cbcSTIMenu.Controls("Format Aging Report").Delete
On Error GoTo 0

If cbcSTIMenu Is Nothing Then

HelpMenuIndex = cbMainMenuBar.Controls("Help").Index

Set cbcSTIMenu = cbMainMenuBar.Controls.Add(Type:=msoControlPopup,
Before:=HelpMenuIndex)
cbcSTIMenu.Caption = "&STI"
cbcSTIMenu.Tag = "STI"
End If

With cbcSTIMenu.Controls.Add(Type:=msoControlButton)
.Caption = "Format Aging Report"
.OnAction = "AgingReportFormat"
End With

"DomThePom" wrote:

> look at delete method od commandbarcontrol object
>
> "Tim" wrote:
>
> > I am creating a new menu called STI to be used by future add-ins. Within
> > that menu, I added a menu item(msControlButton), Format Aging Report, to run
> > a macro. How do I delete Format Aging Report without deleting STI menu?
> >
> > Sub AddMenus()
> >
> > Dim cbMainMenuBar As CommandBar
> > Dim HelpMenuIndex As Integer
> > Dim cbcSTIMenu As CommandBarControl
> >
> > 'Would like to try to delete "Format Aging Report" here instead of current
> > code
> > On Error Resume Next
> > Application.CommandBars("Worksheet Menu Bar").Controls("&STI").Delete
> > On Error GoTo 0
> >
> > Set cbMainMenuBar = Application.CommandBars("Worksheet Menu Bar")
> >
> > HelpMenuIndex = cbMainMenuBar.Controls("Help").Index
> >
> > Set cbcSTIMenu = cbMainMenuBar.Controls.Add(Type:=msoControlPopup,
> > Before:=HelpMenuIndex)
> >
> > cbcSTIMenu.Caption = "&STI"
> >
> > With cbcSTIMenu.Controls.Add(Type:=msoControlButton)
> > .Caption = "Format Aging Report"
> > .OnAction = "AgingReportFormat"
> > End With
> >
> > End Sub

 
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
How to Delete Start Menu Item in "Search" Sub-Menu? =?Utf-8?B?RXVnZW5lIE1hcmtvdw==?= Windows XP Help 3 19th Mar 2006 11:14 AM
Adding Sub Menu Item to Current Custom Menu =?Utf-8?B?UmVuYXRv?= Microsoft Excel Programming 2 19th Dec 2005 12:48 AM
Not able to call a function from custom menu item that is added in word menu(File) jayrm100@yahoo.com Microsoft Word Document Management 0 9th Nov 2005 05:36 AM
I create a menu item using VB, within a custom contacts form. I do not want the item to be visible in other forms or views. How do I do this?? Tore Microsoft Outlook Form Programming 0 10th Mar 2004 01:03 PM
Custom Menu Item specific to a workbook =?Utf-8?B?VG9tbXkgVA==?= Microsoft Excel Programming 1 23rd Jan 2004 07:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:18 PM.