' vbaJPMToolbar_Project: Contains VBA routines for customizing toolbars/menus in MS Project ' Implementation Notes: ' * Unlike the Excel and Word versions, these just get run "manually" ' * The custom toolbar name is captured below, as a constant. Const cJPMCustomToolbarName = "JPM Custom" ' >>> Note <<< If you ever want to change the custom toolbar name, ' run the DeleteJPMCustomToolbar routine "by hand" ' before changing the name. ' 03/20/2006 JPM : First version - but cloned mightiliy from the MS Excel version ' ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ' Copyright (c) 2001-2006 James P. MacLennan All Rights Reserved ' Questions? Comments? Suggestions? Let me know ... www.cazh1.com ' This program is free software; you can redistribute it and/or modify ' it under the terms of the GNU General Public License as published by ' the Free Software Foundation; either version 2 of the License, or ' (at your option) any later version. ' ' This program is distributed in the hope that it will be useful, ' but WITHOUT ANY WARRANTY; without even the implied warranty of ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ' GNU General Public License for more details. ' ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- Option Explicit Sub DeleteJPMCustomToolbar() ' Run this guy to nuke your custom toolbar On Error Resume Next Application.CommandBars(cJPMCustomToolbarName).Delete On Error GoTo 0 End Sub Sub CheckJPMCustomToolbar() ' At startup time, we check for our custom toolbar. If we don't find it, we install it. ' We also make sure that it's visible Dim oCheckBar As CommandBar Dim bCustomExists As Boolean Dim bCustomVisible As Boolean ' Call DeleteJPMCustomToolbar bCustomExists = False bCustomVisible = False For Each oCheckBar In Application.CommandBars If oCheckBar.Name = cJPMCustomToolbarName Then bCustomExists = True bCustomVisible = oCheckBar.Visible End If Next oCheckBar ' Fix what's not right If Not bCustomExists Then Call CreateJPMCustomToolbar If Not bCustomVisible Then Application.CommandBars(cJPMCustomToolbarName).Visible = True End Sub Sub CreateJPMCustomToolbar() ' Create standard set of custom Project menus/toolbars for JPM routines Dim oCheckBar As CommandBar Dim oNewCommandBar As CommandBar Dim oNewMenu As CommandBarPopup Dim oNewButton As CommandBarControl ' Quick sanity check - don't run this routine if the target toolbar exists For Each oCheckBar In Application.CommandBars If oCheckBar.Name = cJPMCustomToolbarName Then MsgBox "Wait a sec - the " & cJPMCustomToolbarName & " toolbar already exists!", vbOKOnly + vbCritical, "Error" Exit Sub End If Next oCheckBar ' Add the custom toolbar With Application.CommandBars Set oNewCommandBar = .Add oNewCommandBar.Enabled = True oNewCommandBar.Name = cJPMCustomToolbarName oNewCommandBar.Position = msoBarTop oNewCommandBar.Visible = True Set oNewCommandBar = Nothing End With ' === Up to this point, it's pretty standard code across all MS applications === ' Now, we are adding menus, buttons, etc. specific to each app. ' Note that the order of the paragraphs below determine the order of the items on your toolbar ' Add a submenu for routines that work with Tasks With Application.CommandBars(cJPMCustomToolbarName) Set oNewMenu = .Controls.Add(Type:=msoControlPopup) oNewMenu.Caption = "Tasks" oNewMenu.DescriptionText = "Common routines for working with Task views" oNewMenu.Enabled = True oNewMenu.TooltipText = "Common routines for working with Task views" oNewMenu.Visible = True Set oNewMenu = Nothing End With '' ' Add menu items to the Resources submenu ' Note that menu items are added in the order listed, top to bottom With Application.CommandBars(cJPMCustomToolbarName).Controls("Tasks").Controls Set oNewButton = .Add(Type:=msoControlButton) oNewButton.BeginGroup = False oNewButton.Caption = "Format for Roadmap" oNewButton.Enabled = True oNewButton.FaceId = 2099 oNewButton.OnAction = "NicePrintPageSetup_RoadmapView" oNewButton.Style = msoButtonIconAndCaption Set oNewButton = Nothing End With ' Add a submenu for routines that work with Resources With Application.CommandBars(cJPMCustomToolbarName) Set oNewMenu = .Controls.Add(Type:=msoControlPopup) oNewMenu.Caption = "Resources" oNewMenu.DescriptionText = "Common routines for working with Resource views" oNewMenu.Enabled = True oNewMenu.TooltipText = "Common routines for working with Resource views" oNewMenu.Visible = True Set oNewMenu = Nothing End With '' ' Add menu items to the Resources submenu ' Note that menu items are added in the order listed, top to bottom With Application.CommandBars(cJPMCustomToolbarName).Controls("Resources").Controls Set oNewButton = .Add(Type:=msoControlButton) oNewButton.BeginGroup = False oNewButton.Caption = "&Set Sort Name" oNewButton.Enabled = True oNewButton.FaceId = 3157 oNewButton.OnAction = "SetSortName" oNewButton.Style = msoButtonIconAndCaption Set oNewButton = Nothing End With ' More simple buttons With Application.CommandBars(cJPMCustomToolbarName) Set oNewButton = .Controls.Add(Type:=msoControlButton) oNewButton.BeginGroup = True oNewButton.Caption = "About" oNewButton.DescriptionText = "About ..." oNewButton.Enabled = True oNewButton.FaceId = 487 oNewButton.OnAction = "AboutDialog" oNewButton.Style = msoButtonIcon oNewButton.TooltipText = "About ..." Set oNewButton = Nothing End With End Sub