Find the Correct Task or Resource Calendar in Microsoft Project VBA
Question details
Identify the calendar used by a task or assigned resource in Microsoft Project VBA without relying on a hard-coded base calendar.

- Product
- Microsoft Project
- Device & OS
- not provided
- Scenario
- A VBA routine needs a calendar object for a task or resource when calculating working time.
- Observed behavior
- The appropriate calendar depends on the task calendar and assigned resources; a schedule can reflect more than one calendar.
Open the project in Microsoft Project and identify a nonblank task to inspect. Check its assigned resources and whether it has a task-specific calendar before choosing a calendar object.
Inspect the Task and Resource Calendars in VBA
Use the resource calendar for a task with one assigned resource and no task-specific calendar; inspect other scheduling calendars when the situation is more complex.
A resource's Calendar is distinct from its base calendar and can include resource-specific working-time exceptions. A task calendar is a separate object.
When multiple calendars affect scheduling, Project calculates a combined schedule. There may be no single calendar object that represents all scheduling constraints.
In Microsoft Project, press Alt+F11 and choose Insert > Module. Open a project with at least one task.
In the VBA editor, inspect the task's Calendar property to see its calendar name. If a task-specific calendar is assigned, use Task.CalendarObject when a method requires a Calendar object; Task.Calendar is a text value.
For a nonblank task at index 1 with exactly one assigned resource and no task-specific calendar, run this macro: Sub InspectResourceCalendar() Dim t As Task Dim cal As Calendar Set t = ActiveProject.Tasks(1) If t Is Nothing Then MsgBox "Task 1 is blank. Choose a nonblank task." Exit Sub End If If t.Resources.Count <> 1 Then MsgBox "This example requires exactly one assigned resource." Exit Sub End If Set cal = t.Resources(1).Calendar MsgBox "Resource calendar: " & cal.Name End Sub
Check t.Resources.Count before accessing Resources(1). For multiple resources, inspect each resource's Calendar; for an unassigned task, inspect the task and project calendars instead. Also check whether the task is configured to ignore resource calendars.

Review Project Data in WPS Office
WPS Office is a free, lightweight alternative for working with exported project data and other Office files. Its familiar interface makes it easy to move between common document formats, although it does not resolve Microsoft Project VBA or scheduling-calendar issues.

Frequently Asked Questions
How do I get the calendar of an assigned resource?
For a task variable named t, use t.Resources(1).Calendar after checking that t.Resources.Count is at least 1. For multiple resources, inspect each resource's calendar.
Why does Task.Calendar cause a type mismatch?
Task.Calendar is a text value. When a method expects a Calendar object and a task-specific calendar is assigned, use Task.CalendarObject instead.
What if the task has no assigned resources?
Do not access t.Resources(1). Check whether the task has a task-specific calendar and consider the project calendar when determining how the task is scheduled.
Does the resource's base calendar include its individual exceptions?
Not necessarily. Use the resource's Calendar to account for its working time and resource-specific exceptions rather than assuming the base calendar alone represents them.
Which calendar does DateDifference use if I omit the calendar argument?
Microsoft Project's DateDifference method defaults to the project calendar when its optional Calendar argument is omitted.




