Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tim Tim is offline
external usenet poster
 
Posts: 408
Default Delete specific menu item from custom menu

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,
Befo=HelpMenuIndex)

cbcSTIMenu.Caption = "&STI"

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

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Delete specific menu item from custom menu

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,
Befo=HelpMenuIndex)

cbcSTIMenu.Caption = "&STI"

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

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
Tim Tim is offline
external usenet poster
 
Posts: 408
Default Delete specific menu item from custom menu

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,
Befo=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,
Befo=HelpMenuIndex)

cbcSTIMenu.Caption = "&STI"

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

End Sub

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
Context-sensitive custom menu item. Murray Excel Programming 7 December 28th 05 04:55 AM
Adding Sub Menu Item to Current Custom Menu Renato Excel Programming 2 December 19th 05 12:48 AM
Excel 2000 Custom Menu Item Larry Bird Excel Discussion (Misc queries) 0 November 8th 05 08:25 PM
Setting OnAction of custom menu item? Ed[_18_] Excel Programming 12 May 10th 04 02:55 PM
Custom Menu Item specific to a workbook Tommy T Excel Programming 1 January 23rd 04 07:34 PM


All times are GMT +1. The time now is 12:34 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"