C
Chris
I have this code tweaked from Rod Gill almost perfect. It is exporting tasks
to an Excel spreadsheet, Unfortunately, I am trying to get it to filter on
the custom field, Text11. If it has a value of "External" then export data
from that task. Otherwise, ignore it and find the next task with that field
set to "External." I've tried every combination for the last 2 hours now and
I just can't get it to filter. Help!
Sub ExportMasterScheduleData()
'Start Excel and create a new workbook
'Create column titles
'Export data and the project title
'Tidy up
Dim xlApp As Excel.Application
Dim xlRange As Excel.Range
Dim Dept As Task
Dim Check As String
'Start Excel and create a new workbook
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.Workbooks.Add
'Create column titles
Set xlRange = xlApp.Range("A1")
With xlRange
.Formula = "Master Schedule Report"
.Font.Bold = True
.Font.Size = 12
.Select
End With
xlRange.Range("A2") = "WBS"
xlRange.Range("B2") = "Project Name"
xlRange.Range("C2") = "Owner"
xlRange.Range("D2") = "Start"
xlRange.Range("E2") = "End"
xlRange.Range("F2") = "Dependencies"
xlRange.Range("G2") = "Dependency Owner"
xlRange.Range("H2") = "Need Date"
xlRange.Range("I2") = "Last Update"
xlRange.Range("J2") = "Deliverables"
xlRange.Range("K2") = "Deliverable Owners"
xlRange.Range("L2") = "Ready Date"""
xlRange.Range("M2") = "ECD"
xlRange.Range("N2") = "Notes"
With xlRange.Range("A2:N2")
.Font.Bold = True
.HorizontalAlignment = xlHAlignCenter
.VerticalAlignment = xlVAlignCenter
End With
'Export data and the project title
Set xlRange = xlRange.Range("A3")
For Each Dept In ActiveProject.Tasks
Check = Dept.Text11
If Not Check = "0" Then
With xlRange
.Range("A3") = Dept.WBS
.Range("B3") = ActiveProject.Name
.Range("C3") = Dept.ResourceNames
.Range("D3") = Dept.Start
.Range("E3") = Dept.Finish
.Range("F3") = Check
.Range("G3") = Dept.Text10
.Range("H3") = Dept.Finish
.Range("O3") = Dept.Text11
End With
Else: End If
Set xlRange = xlRange.Offset(1, 0) 'Point to next row
Check = ""
Next Dept
'Tidy up
xlRange.Range("A3:H3").EntireColumn.AutoFit
Set xlApp = Nothing
End Sub
to an Excel spreadsheet, Unfortunately, I am trying to get it to filter on
the custom field, Text11. If it has a value of "External" then export data
from that task. Otherwise, ignore it and find the next task with that field
set to "External." I've tried every combination for the last 2 hours now and
I just can't get it to filter. Help!
Sub ExportMasterScheduleData()
'Start Excel and create a new workbook
'Create column titles
'Export data and the project title
'Tidy up
Dim xlApp As Excel.Application
Dim xlRange As Excel.Range
Dim Dept As Task
Dim Check As String
'Start Excel and create a new workbook
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.Workbooks.Add
'Create column titles
Set xlRange = xlApp.Range("A1")
With xlRange
.Formula = "Master Schedule Report"
.Font.Bold = True
.Font.Size = 12
.Select
End With
xlRange.Range("A2") = "WBS"
xlRange.Range("B2") = "Project Name"
xlRange.Range("C2") = "Owner"
xlRange.Range("D2") = "Start"
xlRange.Range("E2") = "End"
xlRange.Range("F2") = "Dependencies"
xlRange.Range("G2") = "Dependency Owner"
xlRange.Range("H2") = "Need Date"
xlRange.Range("I2") = "Last Update"
xlRange.Range("J2") = "Deliverables"
xlRange.Range("K2") = "Deliverable Owners"
xlRange.Range("L2") = "Ready Date"""
xlRange.Range("M2") = "ECD"
xlRange.Range("N2") = "Notes"
With xlRange.Range("A2:N2")
.Font.Bold = True
.HorizontalAlignment = xlHAlignCenter
.VerticalAlignment = xlVAlignCenter
End With
'Export data and the project title
Set xlRange = xlRange.Range("A3")
For Each Dept In ActiveProject.Tasks
Check = Dept.Text11
If Not Check = "0" Then
With xlRange
.Range("A3") = Dept.WBS
.Range("B3") = ActiveProject.Name
.Range("C3") = Dept.ResourceNames
.Range("D3") = Dept.Start
.Range("E3") = Dept.Finish
.Range("F3") = Check
.Range("G3") = Dept.Text10
.Range("H3") = Dept.Finish
.Range("O3") = Dept.Text11
End With
Else: End If
Set xlRange = xlRange.Offset(1, 0) 'Point to next row
Check = ""
Next Dept
'Tidy up
xlRange.Range("A3:H3").EntireColumn.AutoFit
Set xlApp = Nothing
End Sub