logo
search
Others

Fix Microsoft Project Application.DateDifference Returns Zero in VBA

Maira MehtabMaira Mehtab Sep 24, 2026 869 views

Question details

The user is experiencing an issue where the VBA Application.DateDifference function incorrectly returns zero, causing division-by-zero and overflow errors in macros.

Product
Microsoft Project
Device & OS
not provided
Scenario
Running VBA scripts to calculate working time differences based on project calendars in Microsoft Project version 2409.
Observed behavior
Application.DateDifference returns 0 instead of the correct time difference, whereas it worked correctly in version 2108. The native DateDiff function works but ignores project calendars.
Before you start

Ensure you have access to the VBA Editor in Microsoft Project and verify that your project calendar is properly configured with valid working times.

Solution 1Recommended

Step Through VBA Code and Inspect Date Variables

Use the built-in VBA debugger to pause code execution and verify the exact date values being passed into the Application.DateDifference function.

Often, functions return zero when invalid or unexpected date values are passed into them. Stepping through the code allows you to monitor variables in real-time.

1
Open the VBA Editor

Press ALT + F11 while in Microsoft Project to open the Visual Basic for Applications (VBA) Editor.

2
Insert a Breakpoint

Locate the macro containing your Application.DateDifference function. Click in the left margin next to the code line to insert a breakpoint (a red dot will appear).

3
Run and Step Through the Code

Run the macro. When execution pauses at the breakpoint, press F8 to step through the code line by line.

4
Inspect Variables

Hover your mouse over the date variables used in the function, or use the Immediate Window (CTRL + G) to print their values and ensure they are valid dates.

Free Microsoft Office alternative

Try WPS Office for Your Data Management and Documentation Needs

While Microsoft Project handles specialized complex project scheduling, you can use WPS Office as a lightweight, free alternative for tracking project tasks, timelines, and budgets using highly familiar spreadsheets and documents.

  1. 1. Download WPS Office: Visit the official WPS website to download and install the free WPS Office suite on your device.
  2. 2. Explore Project Templates: Open WPS Spreadsheets, click on 'New', and browse the template library for Gantt charts or project management trackers.
  3. 3. Manage Project Data: Import your existing Excel or CSV project data to easily track timelines and calculate date differences using standard spreadsheet functions.
Highly compatible with Microsoft Word, Excel, and PowerPoint formatsLightweight installation that consumes fewer system resourcesBuilt-in spreadsheet templates for project tracking and Gantt chartsFree to use with an intuitive, familiar user interface
microsoft office alternative - wps office

Frequently Asked Questions

Why does DateDiff work but Application.DateDifference returns 0?

The native VBA DateDiff function only calculates standard calendar time differences regardless of working hours. Application.DateDifference calculates working time based on a specific project calendar, which may return 0 if the calendar is missing, misconfigured, or affected by a build-specific bug in version 2409.

How do I handle division-by-zero errors in my Microsoft Project VBA macro?

You should add error-handling routines using 'On Error GoTo' or use an 'If' statement to conditionally check if the Application.DateDifference result is zero before using it as a denominator in a division operation.

Can macro security settings affect specific VBA functions like DateDifference?

Yes, strict Trust Center policies in newer MS Project builds can sometimes restrict certain application-level methods from executing properly. Ensuring your macro file is saved in a Trusted Location can help bypass these restrictions.