Option Explicit
Const xlToRight = -4161
Const xlDown = -4121
Const COLRECORDID = 1
Const COLFMIDX = 2
Const COLJOB = 3
Const COLUNITNAME = 4
Const COLSHOTNAME = 5
Const COLDEPTNAME = 6
Const COLJOBTYPE = 7
Const COLFULLNAME = 8
Const COLSTART = 9
Const COLBID = 10
Const COLPAD = 11
Const COLEXTDELAY = 12
Const COLFINISH = 13
Const COLWORK = 14
Const COLUNIQUEID = 15
Const COLTNOTES = 16
Const COLLOGINID = 17
Const COLCDD = 18
Const COLSTATUSM = 19
Const COLTASKSTAT = 20
Const COLSSSTART = 21
Const COLSSDUE = 22
Const COLSCHCHANGES = 23
Const TEMPLATEPROJ = "C:\FMexport\FM Import Project 2.mpt"
Global filtername As String
Global count As Long
Global count2 As Long
Global count3 As Long
Global outwardfile As String
Global inwardfile As String
Public OutArray() As Variant
Public newtaskarray() As Variant
Public filterinitials As String
Public OutArrayALL() As Variant
Global unitname As String
Global deptname As String
Global dptcnt As Integer
Global untcnt As Integer
Global resuming As Boolean
Sub MSPExport()
If forceclose = True Then Exit Sub
If resuming = True Then GoTo andnowformynexttrick
Dim dup As task
Set dup = CheckForDupRecordIDs()
If Not dup Is Nothing Then
Call MsgBox(Prompt:="Duplicate Task id" & dup & ": " & dup.Text18 & " for " & dup.OutlineParent.name, _
Buttons:=vbExclamation, title:="Export Error")
Exit Sub
End If
andnowformynexttrick:
Dim i As Integer, j As Integer
Dim selectedCount1 As Integer
For i = 0 To MSPExportForm.ListBox1.ListCount - 1
If MSPExportForm.ListBox1.Selected(i) Then selectedCount1 = selectedCount1 + 1
Next i
Dim selectedcount2 As Integer
For j = 0 To MSPExportForm.ListBox2.ListCount - 1
If MSPExportForm.ListBox2.Selected(j) Then selectedcount2 = selectedcount2 + 1
Next j
ReDim OutArray(ActiveProject.Tasks.count, 50)
count = 0
ReDim newtaskarray(ActiveProject.Tasks.count, 50)
count2 = 0
ReDim OutArrayALL(ActiveProject.Tasks.count, 30)
count3 = 0
OutArray(count, COLRECORDID - 1) = "RecordID"
OutArray(count, COLFMIDX - 1) = "fmidx"
OutArray(count, COLJOB - 1) = "job"
OutArray(count, COLNAME - 1) = "name"
OutArray(count, COLJOBTYPE - 1) = "task"
OutArray(count, COLSTART - 1) = "Start"
OutArray(count, COLFINISH - 1) = "actualEnd"
OutArray(count, COLFULLNAME - 1) = "userName"
OutArray(count, COLDEPTNAME - 1) = "Dept"
OutArray(count, COLWORK - 1) = "Work"
OutArray(count, COLTNOTES - 1) = "taskNotes"
OutArray(count, COLUNIQUEID - 1) = "uniqueID"
OutArray(count, COLUNITNAME - 1) = "Unit"
OutArray(count, COLBID - 1) = "cost1"
OutArray(count, COLPAD - 1) = "cost2"
OutArray(count, COLEXTDELAY - 1) = "EXTdelay"
OutArray(count, COLSTATUSM - 1) = "statusMaster"
OutArray(count, COLTASKSTAT - 1) = "taskStatus"
OutArray(count, COLLOGINID - 1) = "loginID"
OutArray(count, COLSSSTART - 1) = "subsetStart"
OutArray(count, COLSSDUE - 1) = "subsetDue"
OutArray(count, COLSCHCHANGES - 1) = "ScheduleChange"
count = count + 1
OutArrayALL(count3, COLRECORDID - 1) = "RecordID"
OutArrayALL(count3, COLFMIDX - 1) = "fmidx"
OutArrayALL(count3, COLJOB - 1) = "job"
OutArrayALL(count3, COLNAME - 1) = "name"
OutArrayALL(count3, COLJOBTYPE - 1) = "task"
OutArrayALL(count3, COLSTART - 1) = "Start"
OutArrayALL(count3, COLFINISH - 1) = "actualEnd"
OutArrayALL(count3, COLFULLNAME - 1) = "userName"
OutArrayALL(count3, COLDEPTNAME - 1) = "Dept"
OutArrayALL(count3, COLWORK - 1) = "Work"
OutArrayALL(count3, COLTNOTES - 1) = "taskNotes"
OutArrayALL(count3, COLUNIQUEID - 1) = "uniqueID"
OutArrayALL(count3, COLUNITNAME - 1) = "Unit"
OutArrayALL(count3, COLBID - 1) = "bid"
OutArrayALL(count3, COLPAD - 1) = "pad"
OutArrayALL(count3, COLEXTDELAY - 1) = "EXTdelay"
OutArrayALL(count3, COLCDD - 1) = "clientDueDate"
OutArrayALL(count3, COLSTATUSM - 1) = "statusMaster"
OutArrayALL(count3, COLTASKSTAT - 1) = "taskStatus"
OutArrayALL(count3, COLLOGINID - 1) = "loginID"
OutArrayALL(count3, COLSSSTART - 1) = "subsetStart"
OutArrayALL(count3, COLSSDUE - 1) = "subsetDue"
OutArrayALL(count3, COLSCHCHANGES - 1) = "ScheduleChange"
count3 = count3 + 1
newtaskarray(count2, COLRECORDID - 1) = "RecordID"
newtaskarray(count2, COLFMIDX - 1) = "fmidx"
newtaskarray(count2, COLNAME - 1) = "name"
newtaskarray(count2, COLJOBTYPE - 1) = "task"
newtaskarray(count2, COLSTART - 1) = "Start"
newtaskarray(count2, COLJOB - 1) = "Job"
newtaskarray(count2, COLFINISH - 1) = "actualEnd"
newtaskarray(count2, COLFULLNAME - 1) = "userName"
newtaskarray(count2, COLDEPTNAME - 1) = "deptName"
newtaskarray(count2, COLWORK - 1) = "Work"
newtaskarray(count2, COLTNOTES - 1) = "taskNotes"
newtaskarray(count2, COLDEPTNAME - 1) = "Dept"
newtaskarray(count2, COLUNIQUEID - 1) = "uniqueID"
newtaskarray(count2, COLUNITNAME - 1) = "Unit"
newtaskarray(count2, COLBID - 1) = "bid"
newtaskarray(count2, COLPAD - 1) = "pad"
newtaskarray(count2, COLEXTDELAY - 1) = "EXTdelay"
newtaskarray(count2, COLSTATUSM - 1) = "statusMaster"
newtaskarray(count2, COLTASKSTAT - 1) = "taskStatus"
newtaskarray(count2, COLCDD - 1) = "clientDueDate"
newtaskarray(count2, COLLOGINID - 1) = "loginID"
newtaskarray(count2, COLSSSTART - 1) = "subsetStart"
newtaskarray(count2, COLSSDUE - 1) = "subsetDue"
newtaskarray(count2, COLSCHCHANGES - 1) = "ScheduleChange"
count2 = count2 + 1
If selectedCount1 = 0 Or selectedcount2 = 0 Then
MsgBox ("You must select one or more shows from the list")
Else
Dim t As task
For Each t In ActiveProject.Tasks
If isittheend(t) = True And t.Text1 <> "Subset" Then
AddtoallArray t
For i = 0 To MSPExportForm.ListBox1.ListCount - 1
If MSPExportForm.ListBox1.Selected(i) Then
For j = 0 To MSPExportForm.ListBox2.ListCount - 1
If MSPExportForm.ListBox2.Selected(j) Then
If t.Text11 = MSPExportForm.ListBox2.List(j) And t.Text3 = MSPExportForm.ListBox1.List(i) Then
If t.Text1 <> "Subset" Then AddtoArrays t
End If
End If
Next j
End If
Next i
End If
Next t
outwardfile = "MSPExport_" & wayinit & "_options_" & testorreal & ".xls"
inwardfile = "FMExport_" & testorreal & "_" & wayinit & ".xls"
'create a new workbook
Dim ExcelApp As Object, NewBook As Object, Sheet As Object, alltsheet As Object
Dim newtsheet As Object, newtasks As Object, AllTasks As Object
Dim theoutput As WorkBook, theoutput2 As WorkBook, alloutput As WorkBook
retry:
Set ExcelApp = CreateObject("Excel.Application")
err.Clear
On Error Resume Next
Set NewBook = ExcelApp.Workbooks.Add
If err.Number <> 0 Then GoTo retry
On Error GoTo 0
Set Sheet = NewBook.ActiveSheet
Set theoutput = ExcelApp.ActiveWorkbook
Set newtasks = ExcelApp.Workbooks.Add
Set newtsheet = newtasks.ActiveSheet
Set theoutput2 = ExcelApp.ActiveWorkbook
Set AllTasks = ExcelApp.Workbooks.Add
Set alltsheet = AllTasks.ActiveSheet
Set alloutput = ExcelApp.ActiveWorkbook
ExcelApp.Visible = True
ExcelApp.ScreenUpdating = True
Sheet.Range(Sheet.Cells(1, 1), Sheet.Cells(ActiveProject.Tasks.count, 50)).value = OutArray
newtsheet.Range(newtsheet.Cells(1, 1), newtsheet.Cells(ActiveProject.Tasks.count, 50)).value = newtaskarray
alltsheet.Range(alltsheet.Cells(1, 1), alltsheet.Cells(ActiveProject.Tasks.count, 50)).value = OutArrayALL
ExcelApp.DisplayAlerts = False