Ruckley
02-04-2011, 10:31 AM
Anyone know the code for the "Window" menu item? Want to disable it without referring to it directly.
thhanks.
If you are referring to the menu for the app's window, I think you'll want to search for API mehods.
IBihy
02-09-2011, 05:40 PM
Hi,
I've done this before. The below code is has two parts:
Menu Builder and Menu Remover: Checks if the menu exists, else builds it, i.e. inserts it before "Help". When the application ends, menu will be removed.
Event Handler module: Handles the click events from the menu.Menu Builder:
Sub MenueBuilder()
Dim intPlaceMenue As Integer
Dim lngItemCt As Long
Dim mcbProcessEarnedValue As CommandBar
Dim mcbPopUpProcessEarnedValue As CommandBarPopup
Dim mcbPopUpDataSources As CommandBarPopup
Dim mcbPopUpEvaluation As CommandBarPopup
Dim mcbPopupGraphics As CommandBarPopup
Dim mcbButtonProcessEarnedValue As CommandBarControl
Dim mcbButtonDataSources As CommandBarControl
Dim mcbButtonEvaluation As CommandBarControl
Dim mcbButtonGraphics As CommandBarControl
' Prepare the standard menue to hold the EarnedValue Reporting macros
' Check if Earned Value menue already exists, and delete it to avoid duplicates
Do
boolMenueExists = MenueExists("Worksheet Menu Bar", "EV Reporting")
If boolMenueExists = True Then
Application.CommandBars("Worksheet Menu Bar").Controls("EV Reporting").Delete
Else
Exit Do
End If
Loop
' Point to the standard menue bar
Set mcbProcessEarnedValue = Application.CommandBars("Worksheet Menu Bar")
' ensure that the Earned Value Reporting menue will appear before the help menue
' This looks goofy, but the subtle difference between 0 and 1 keeps the code
' working. Controls.Count returns the amount of menues in the menue bar. Yet,
' the counting of the spots where the menues appear starts with 0. Thus the
' expression below causes the new menue to be inserted right before the help menue.
intPlaceMenue = mcbProcessEarnedValue.Controls.Count
Set mcbPopUpProcessEarnedValue = mcbProcessEarnedValue.Controls.Add( _
Type:=msoControlPopup, Before:=intPlaceMenue, temporary:=True)
' menue title
mcbPopUpProcessEarnedValue.Caption = "EV Reporting"
' DataSources and sub menue
Set mcbPopUpDataSources = mcbPopUpProcessEarnedValue.Controls.Add(Type:=msoControlPopup)
With mcbPopUpDataSources
.Visible = True
.Caption = "Data Sources..."
.TooltipText = "Manage data and import from external sources"
End With
' for testing purposes
Set mcbButtonDataSources = mcbPopUpDataSources.Controls.Add
With mcbButtonDataSources
.Visible = True
.Caption = "Check INI File"
.TooltipText = "for testing of ini file"
.OnAction = "HandleINIFileRequests"
End With
' not sure if needed
Set mcbButtonDataSources = mcbPopUpDataSources.Controls.Add
With mcbButtonDataSources
.Visible = False
.Caption = "Source directory"
.TooltipText = "Set source directory"
.OnAction = "HandleDirectoryRequests"
End With
Set mcbButtonDataSources = mcbPopUpDataSources.Controls.Add
With mcbButtonDataSources
.Visible = True
.Caption = "Import data"
.TooltipText = "Import data from other files"
' lngRunNumber = 0
.OnAction = "HandleCountryImportRequests"
End With
Set mcbButtonDataSources = mcbPopUpDataSources.Controls.Add
With mcbButtonDataSources
.Visible = True
.Caption = "Dump Stack"
.TooltipText = "Dumps module stack"
' lngRunNumber = 0
.OnAction = "HandleDataSources"
End With
' Evaluation
Set mcbPopUpEvaluation = mcbPopUpProcessEarnedValue.Controls.Add(Type:=msoControlPopup)
With mcbPopUpEvaluation
.Visible = True
.Caption = "Evaluation..."
.TooltipText = "Initiate evaluation by country, index or full report"
End With
Set mcbButtonEvaluation = mcbPopUpEvaluation.Controls.Add
With mcbButtonEvaluation
.Visible = True
.Caption = "Report Options..."
.TooltipText = "Select report options"
.OnAction = "HandleReportOptions"
End With
Set mcbButtonEvaluation = mcbPopUpEvaluation.Controls.Add
With mcbButtonEvaluation
.Visible = True
.Caption = "Create Report"
.TooltipText = "Build report from options"
.OnAction = "HandleCreateReport"
End With
' Graphics
Set mcbPopupGraphics = mcbPopUpProcessEarnedValue.Controls.Add(Type:=msoControlPopup)
With mcbPopupGraphics
.Visible = True
.Caption = "Generate Diagrams..."
.TooltipText = "Generate and display diagrams"
End With
Set mcbButtonGraphics = mcbPopupGraphics.Controls.Add
With mcbButtonGraphics
.Visible = True
.Caption = "Index Diagrams"
.TooltipText = "Generates index diagrams of the selected indices"
.OnAction = "HandleIndexDiagrams"
End With
Set mcbButtonGraphics = mcbPopupGraphics.Controls.Add
With mcbButtonGraphics
.Visible = True
.Caption = "Process Diagrams"
.TooltipText = "Generates process diagrams of the selected indices"
.OnAction = "HandleProcessDiagrams"
End With
Set mcbButtonGraphics = mcbPopupGraphics.Controls.Add
With mcbButtonGraphics
.Caption = "Full Report"
.TooltipText = "Generates index and process diagrams"
.OnAction = "HandleFullRptDiagrams"
End With
End Sub
Sub MenueRemover()
Dim lngItemCt As Long
End If
Application.CommandBars("Worksheet Menu Bar").Controls("EV Reporting").Delete
lngRunNumber = 0
End Sub
Function MenueExists(strCommandBarName As String, strMenueName As String) As Boolean
Dim lngItemCt As Long
Dim mcbProcessEarnedValue As CommandBar
Dim mcbPopUpEarnedValue As CommandBarPopup
Dim intPlaceMenue As Integer
Dim varHasControl As Variant
Set mcbProcessEarnedValue = Application.CommandBars(strCommandBarName)
intPlaceMenue = mcbProcessEarnedValue.Controls.Count
Set varHasControl = mcbProcessEarnedValue.Controls(intPlaceMenue - 1)
If varHasControl.Caption = "&Window" Then
MenueExists = False
Else
MenueExists = True
End If
End Function
Event Handler module:
Sub HandleINIFileRequests()
' actually, invoke your business logic here
MsgBox "Greetings from the INI file requests handler", vbOKOnly, "EventHandler"
End Sub
Sub HandleDirectoryRequests()
' actually, invoke your business logic here
MsgBox "Greetings from the directory requests handler", vbOKOnly, "EventHandler"
End Sub
Sub HandleCountryImportRequests()
' actually, invoke your business logic here
MsgBox "Greetings from the country import requests handler", vbOKOnly, "EventHandler"
End Sub
Sub HandleDataSources()
' actually, invoke your business logic here
MsgBox "Greetings from the data source manager", vbOKOnly, "EventHandler"
End Sub
Sub HandleReportOptions()
' actually, invoke your business logic here
MsgBox "Greetings from the Report Options window", vbOKOnly, "EventHandler"
End Sub
Sub HandleCreateReport()
' actually, invoke your business logic here
MsgBox "Greetings from the Create Report requests handler", vbOKOnly, "EventHandler"
End Sub
Sub HandleIndexDiagrams()
' actually, invoke your business logic here
MsgBox "Greetings from the index diagram generator", vbOKOnly, "EventHandler"
End Sub
Sub HandleProcessDiagrams()
' actually, invoke your business logic here
MsgBox "Greetings from the process diagram generator", vbOKOnly, "EventHandler"
End Sub
Sub HandleFullRptDiagrams()
' actually, invoke your business logic here
MsgBox "Greetings from the full report diagram generator", vbOKOnly, "EventHandler"
End Sub
Hope this points you in the right direction.
Isabella
mancubus
02-10-2011, 12:46 AM
visit:
xl2003: http://www.rondebruin.nl/menuid.htm
xl2007/2010: http://www.rondebruin.nl/ribbon.htm
Jan Karel Pieterse
02-10-2011, 12:53 AM
Anyone know the code for the "Window" menu item? Want to disable it without referring to it directly.
thhanks.
Like this:
Application.commandbars("worksheet menu bar").FindControl(id:=30009,recursive:=true).Enabled=False
Ruckley
02-14-2011, 03:51 AM
Ah, 30009. That's the one.
Many thanks.
Jan Karel Pieterse
02-14-2011, 04:14 AM
Find the ID's here:
www.jkp-ads.com/download.asp#xlmenufundict (http://www.jkp-ads.com/download.asp#xlmenufundict)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.