Project 2007 : How to delete an Organizer item using a macro form multiple projects

Recently, I worked on an issue where we had to delete unused calendar from several projects. The best way to clean this is to going to Organizer [Alt + T + G] -> Calendars -> select the calendar and delete the same. However, performing this action for several projects is a lengthy job. Here is the simple Marco that will help.

Before running the macro let's ensure that the item is not associated with any of the Resources or Tasks before deleting the same.

First create a list of projects in “Projects.txt” – each project name on a new line.

  • Save this file on the C:\
  • Open the Project Pro
  • Go to the Visual Basic Editor
  • Copy and paste the below Macro in any of the Module.

Function RemoveCalendars()

' Macro RemoveCalendars

' Macro Recorded by Maulik Raval.

On Error Resume Next

i = 0

fspec = "c:\Projects.txt"

Set fso = CreateObject("Scripting.FileSystemObject")

Set ots = fso.OpenTextFile("c:\Projects.txt", 1)

Do Until ots.AtEndOfStream

k(i) = ots.readline

i = i + 1

Loop

Set prjApp = CreateObject("Msproject.Application")

For j = 0 To i - 1

If prjApp.FileOpen("<>\" & k(j), False) = True Then

OrganizerDeleteItem Type:=5, FileName:=k(j), Name:="CalendarName"

prjApp.FileSave

bool = prjApp.FileCloseEx(pjSave, , True)

End If

Next j

Set prjProject = Nothing

Set prjNewProject = Nothing

Set prjApp = Nothing

End Function

  • Run this macro.

Here Type 5 Indicates Calendar.

Below are the other Types and what it indicates.

Type:=0 = View
Type:=8 = Forms
Type:=5 = Calendar
Type:=4 = Reports
Type:=1 = Tables
Type:=6 = Toolbars
Type:=10 = Groups
Type:=3 = Modules
Type:=2 = Filters
Type:=7 = Maps
Type:=9 = Fields

Enjoy!!!!