Quantcast
Channel: Project Customization and Programming forum
Viewing all articles
Browse latest Browse all 5347

Export Project Tasks to Excel using VBA by Custom Field

$
0
0

I want to export tasks to Excel in a Custom Field with specific text. Only export tasks which have "Yes" in a selected Custom Field (Text20 for example) to Excel.

Below is what I have so far, but It leaves empty rows in spreadsheet where tasks do not match the criteria. I need a contiguous list of tasks meeting the "Yes" criteria. I'm thinking the script is formatted incorrectly. Need Help refining this query.

I would also like it to create a spreadsheet instead of opening an existing spreadsheet.

Sub ExportToExcel()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim proj As Project
Dim t As Task
Dim pj As Project
Set pj = ActiveProject
Set xlApp = New Excel.Application
xlApp.Visible = True
AppActivate "Microsoft Excel"
Set xlBook = xlApp.Workbooks.Open("C:\Templates\exporttest.xlsm")
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"
xlSheet.Cells(4, 5).Value = "Task Notes"
xlSheet.Cells(4, 6).Value = "Summary Task"
xlSheet.Cells(4, 7).Value = "Predecessor Tasks"
For Each t In pj.Tasks
If t.Text20 = "Yes" Then
    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
    xlSheet.Cells(t.ID + 4, 5).Value = t.Notes
    xlSheet.Cells(t.ID + 4, 6).Value = t.Summary
    xlSheet.Cells(t.ID + 4, 7).Value = t.Predecessors
End If
Next t
End Sub


Viewing all articles
Browse latest Browse all 5347

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>