Others

Find the Correct Task or Resource Calendar in Microsoft Project VBA

Steve KSteve K Nov 20, 2026 868 views

Question details

Identify the calendar used by a task or assigned resource in Microsoft Project VBA without relying on a hard-coded base calendar.

Find the Correct Task or Resource Calendar in Microsoft Project VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In Microsoft Project, press Alt+F11 and choose Insert > Module. Open a project with at least one task.

2
Inspect the task calendar

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.

3
Use the resource calendar for the simple case

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

4
Handle other assignments

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.

Inspect the Task and Resource Calendars in VBA
DateDifference default: The Calendar argument for Project's DateDifference method is optional. If omitted, it defaults to the project calendar, not necessarily the assigned resource's calendar.
Free Microsoft Office alternative

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.

Review exported task and resource lists in WPS SpreadsheetCompatible with Microsoft Excel XLSX, Word DOCX, and PowerPoint PPTX formatsFamiliar interface for an easier transition from Microsoft OfficeFree, lightweight tools for everyday document work
QA img-9

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.