VBA & Macro Problems

Fix Microsoft Project VBA Macro to Expand All Descendants of a Selected Task

Aamir Naveed AkramAamir Naveed Akram Nov 13, 2026 868 views

Question details

The user needs a VBA macro for Microsoft Project that fully expands a selected summary task and every descendant subtask, not only the previously shown outline level.

Fix Microsoft Project VBA Macro to Expand All Descendants of a Selected Task
Product
Microsoft Project VBA
Device & OS
not provided
Scenario
The user selects a summary task and wants to expand only that branch completely for review or editing.
Observed behavior
OutlineShowSubTasks stops at the previously displayed outline level, leaving lower descendants collapsed.
Before you start

Make sure the Microsoft Project file contains summary tasks with nested subtasks, and enable the Developer tab so the Visual Basic Editor is accessible.

Solution 1Recommended

Use a Recursive VBA Macro to Expand All Descendants of a Selected Microsoft Project Task

Use this method when OutlineShowSubTasks stops at the previously displayed outline level and you need a true expand-all action limited to the selected task.

The built-in OutlineShowSubTasks method expands only the next outline level below the current display state. A recursive subroutine walks through the selected task's OutlineChildren collection and calls the expansion on each child, so no descendant is left collapsed.

1
Open the Microsoft Project Visual Basic Editor

In Microsoft Project, press Alt+F11. Or enable the Developer tab via File > Options > Customize Ribbon, then click Developer > Visual Basic.

2
Insert a VBA module

In the Project Explorer pane, right-click the active VBAProject, choose Insert > Module, and open the new module window.

3
Paste the recursive expansion code

Sub ExpandAllDescendants() Dim t As Task If ActiveSelection.Tasks.Count = 0 Then Exit Sub Set t = ActiveSelection.Tasks(1) ShowSubtasksRecursive t End Sub Sub ShowSubtasksRecursive(t As Task) Dim child As Task t.OutlineShowSubtasks For Each child In t.OutlineChildren ShowSubtasksRecursive child Next child End Sub

4
Run the macro on the selected task

Select a summary task in your project, then click anywhere inside ExpandAllDescendants and press F5. You can also go to Run > Run Sub/UserForm or View > Macros > Run.

Use a Recursive VBA Macro to Expand All Descendants of a Selected Microsoft Project Task
All descendants expand: The macro expands the selected summary task and every OutlineChild recursively, independent of the outline level that was previously displayed.
Free Microsoft Office alternative

Use WPS Office as a Free Alternative for Editing Project Task Lists and Office Documents

WPS Office cannot run Microsoft Project VBA macros, but it is a free, lightweight Microsoft Office alternative that opens everyday task lists, spreadsheets, documents, and presentations with a familiar ribbon interface. Export your Microsoft Project task data to Excel and continue editing in WPS Spreadsheets without paying for Microsoft Office.

  1. 1. Download WPS Office: Go to the official WPS website and download WPS Office for Windows, macOS, Linux, iOS, or Android.
  2. 2. Export the Microsoft Project task list: In Microsoft Project, save or export the task list to an Excel workbook (.xlsx) that WPS Spreadsheets can open.
  3. 3. Open and edit in WPS Spreadsheets: Launch WPS Office, open the .xlsx task list in WPS Spreadsheets, and edit, filter, or share the data using familiar spreadsheet tools.
Free, lightweight Office suite with Writer, Spreadsheets, Presentation, and PDF tools.Opens and saves Microsoft Office formats such as .xlsx, .docx, and .pptx.Use WPS Spreadsheets to edit Microsoft Project task lists exported to Excel.Familiar ribbon UI makes migration from Microsoft Office easy.
microsoft office alternative - wps office

Frequently Asked Questions

Why does OutlineShowSubTasks stop at the previously displayed outline level?

In Microsoft Project, OutlineShowSubTasks expands one displayed outline level below the current state. If a lower level was already shown, the method may appear to stop early, so a recursive routine is needed to expand every descendant.

How do I run the recursive VBA macro in Microsoft Project?

Open the Visual Basic Editor with Alt+F11, insert a module, paste the recursive code, select the summary task, then press F5 with the cursor inside the ExpandAllDescendants sub.

What is the correct way to pass a Task object to a VBA subroutine?

Use the call without parentheses, such as ShowSubtasksRecursive t or ShowSubtasksRecursive child. Adding parentheses around an object argument can trigger a Compile error: Type mismatch.

Can I expand only the selected task and its descendants without expanding the whole project?

Yes. The macro reads ActiveSelection.Tasks(1) and recurses through the selected task's OutlineChildren collection, so unrelated summary tasks remain unchanged.

Can WPS Office run Microsoft Project VBA macros?

No. WPS Office does not run Microsoft Project VBA macros, but you can export task data to Excel and use WPS Spreadsheets as a free alternative for viewing and editing the task list.