Others

Export a Microsoft Project Timeline to Excel with VBA

Bushra ParveenBushra Parveen Nov 13, 2026 868 views

Question details

Export a Microsoft Project Timeline to Excel with a VBA macro, restore the previous view, and use Gantt Chart as the project’s starting view.

Export a Microsoft Project Timeline to Excel with VBA
Product
Microsoft Project and Microsoft Excel
Device & OS
not provided
Scenario
A macro needs to switch to Timeline, copy it for use in Excel, and return to the view that was active before the export.
Observed behavior
The Timeline needs to be pasted into Excel after export, and the correct built-in view name is Gantt Chart.
Before you start

Open the project and make sure its Timeline contains the tasks you want to export. In Project, open the VBA editor with Alt+F11 and confirm that Excel is installed and available for automation.

Solution 1Recommended

Export the Timeline and restore the previous Project view

Use a Project VBA macro to copy the Timeline as an image, paste it into a new Excel workbook, and restore the view that was active before the export.

TimelineExport copies the Timeline to the clipboard; it does not create an Excel file by itself. The macro below uses late binding to open Excel and paste the copied image.

Restoring the previous view and always ending in Gantt Chart are different goals. If you want Gantt Chart after every run instead, replace the restoration line with ViewApply Name:="Gantt Chart".

1
Add a VBA module

In Microsoft Project, press Alt+F11. In the VBA editor, select your project and choose Insert > Module.

2
Paste the export macro

Paste this code into the module: Sub ExportTimelineToExcel() Dim CurView As String Dim xlApp As Object Dim xlBook As Object Dim xlSheet As Object On Error GoTo ExportError CurView = ActiveProject.CurrentView ViewApplyEx Name:="Timeline", ApplyTo:=0 TimelineExport ExportWidth:=940 ViewApply Name:=CurView Set xlApp = CreateObject("Excel.Application") xlApp.Visible = True Set xlBook = xlApp.Workbooks.Add Set xlSheet = xlBook.Worksheets(1) xlSheet.Paste Destination:=xlSheet.Range("A1") Exit Sub ExportError: MsgBox "Export failed: " & Err.Description, vbExclamation On Error Resume Next If Len(CurView) > 0 Then ViewApply Name:=CurView End Sub

3
Run the macro

Place the cursor inside ExportTimelineToExcel and press F5. Check the new Excel workbook for the Timeline image pasted at cell A1.

4
Save the workbook

In Excel, select File > Save As and choose a location and workbook format.

Export the Timeline and restore the previous Project view
Timeline toggle behavior: TimelineViewToggle reverses the Timeline pane’s current state; it does not explicitly set it to off. Do not add it as an unconditional off command. The pasted Timeline is an image, not editable project data.
Free Microsoft Office alternative

View Excel Timeline Exports in WPS Spreadsheet

WPS Office is a free, lightweight Office alternative with a familiar interface and compatibility with Excel files, making it easy to move a workbook containing a Timeline image. It does not run the Microsoft Project macro or fix Project Timeline behavior.

Open and review Excel workbooks containing exported Timeline imagesCompatible with Microsoft Excel XLSX and XLS formatsFamiliar spreadsheet interface for an easier transition from ExcelFree, lightweight office suite for everyday document work
microsoft office alternative - wps office

Frequently Asked Questions

Does TimelineExport create an Excel workbook?

No. TimelineExport copies the Timeline to the clipboard. Use Excel automation to create or open a workbook, then paste the copied image into a worksheet.

How do I return to the view I was using before the macro?

Store ActiveProject.CurrentView before switching views, then call ViewApply Name:=CurView after exporting the Timeline.

Why does ViewApply fail with the name Gantt view?

The default built-in view is named Gantt Chart. Use ViewApply Name:="Gantt Chart", unless you have created a custom view with a different name.

Can I use TimelineViewToggle to make sure the Timeline is off?

Not by itself. TimelineViewToggle reverses the current state, so it can turn the Timeline on if it is already off. Use it only when you know the current state.

Can I edit the exported Timeline tasks in Excel?

The Timeline copied by TimelineExport is pasted as an image, so its tasks are not editable as worksheet cells. Export project data separately if you need editable task information.