Export a Microsoft Project Timeline to Excel with VBA
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.

- 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.
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.
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".
In Microsoft Project, press Alt+F11. In the VBA editor, select your project and choose Insert > Module.
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
Place the cursor inside ExportTimelineToExcel and press F5. Check the new Excel workbook for the Timeline image pasted at cell A1.
In Excel, select File > Save As and choose a location and workbook format.

Use Gantt Chart as the starting view
Apply the built-in Gantt Chart view before saving the project when you want to start from that view.
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.

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.




