Exporting MS Project data to excel in RRS feed

  • Question

  • The following program is in Project VBA & runs fine, but when I try to convert it into, I get the following error

    1                     Type 'Excel.Application' is not defined.

    2                     Type 'Excel.Range' is not defined.

    3                     Type 'Excel.Workbook' is not defined.           

    4                     Type 'Excel.Worksheet' is not defined.          

    Sub ExportToExcel()

    Dim xlApp As Excel.Application

    Dim xlBook As Excel.Workbook

    Dim xlSheet As Excel.Worksheet

    Dim xlRange As Excel.Range

    Dim proj As Project

    Dim t As Task

    Dim pj As Project

    Set pj = ActiveProject

    Set xlApp = CreateObject("Excel.Application")

    xlApp.Visible = True

    AppActivate "Microsoft Excel"

    Set xlBook = xlApp.Workbooks.Open("D:\Addin\Addin.xlsx")

    Set xlSheet = xlBook.Worksheets(1)

    xlSheet.Cells(1, 1).Value = "Project Name"

    xlSheet.Cells(1, 2).Value = pj.Name

    xlSheet.Cells(2, 1).Value = "Project Title"

    xlSheet.Cells(2, 2).Value = pj.Title

    xlSheet.Cells(4, 1).Value = "Task ID"

    xlSheet.Cells(4, 2).Value = "Task Name"

    xlSheet.Cells(4, 3).Value = "Task Start"

    xlSheet.Cells(4, 4).Value = "Task Finish"

    For Each t In pj.Tasks

        xlSheet.Cells(t.ID + 4, 1).Value = t.ID

        xlSheet.Cells(t.ID + 4, 2).Value = t.Name

        xlSheet.Cells(t.ID + 4, 3).Value = t.Start

        xlSheet.Cells(t.ID + 4, 4).Value = t.Finish

    Next t

    End Sub


    Tuesday, December 2, 2014 12:26 PM

All replies

  • RCKeni,

    I don't use, but the normal reason for this type of error with VBA is not having a reference set for the Excel object library. I'd check your references in the environment.

    Hope this helps.


    Tuesday, December 2, 2014 4:08 PM