Below I've copied over the main loop (where the bulk of the time is spent) of
code from one of my macros in the hope that it will help in determining why
it runs so slow. Note that most of the time (as in the code herein), I'm
running code in MS Project but am dumping information into Excel. Could the
slowness be because I'm crossing over between applications or object models?
I just assumed that MS Project alone was the problem because of the speed I
always experience from Excel-alone code.
For j = 1 To NumFiles
Application.StatusBar = j - 1 & " files complete . . . working on " &
ProjFiles(j)
FileOpen Name:=PthToMPP & ProjFiles(j), ReadOnly:=True,
FormatID:="MSProject.MPP", openpool:=pjDoNotOpenPool 'open MSP file
For Each T In ActiveProject.Tasks
If Not T Is Nothing Then
If T.SplitParts(T.SplitParts.Count).start <= datWkEnding2 And
T.RemainingWork > 0 Then
bolBothWE = False
If T.SplitParts(T.SplitParts.Count).start <= datWkEnding
Then bolBothWE = True
For Each A In T.Assignments
If A.ResourceType = pjResourceTypeWork And
A.RemainingWork > 0 Then
With xlSheet
strScratch = ""
If T.Critical = True Then strScratch = "Y"
If bolBothWE = True Then
.Cells(OutRow, WECOL).Value =
DateFormat(datWkEnding, pjDate_mm_dd_yyyy)
Else
.Cells(OutRow, WECOL).Value =
DateFormat(datWkEnding2, pjDate_mm_dd_yyyy)
End If
.Cells(OutRow, RSRCCOL).Value = A.ResourceName
.Cells(OutRow, PRIORCOL).Value = ProjPrior(j)
.Cells(OutRow, PROJCOL).Value = ProjFiles(j) & "
#" & ProjNum(j)
.Cells(OutRow, TASKCOL).Value = T.Name & " (" &
T.OutlineParent.Name & ")"
.Cells(OutRow, NOTECOL).Value = T.Notes
.Cells(OutRow, IDCOL).Value = T.ID
.Cells(OutRow, STARTCOL).Value =
DateFormat(T.start, pjDate_mm_dd_yyyy)
.Cells(OutRow, FINISHCOL).Value =
DateFormat(T.finish, pjDate_mm_dd_yyyy)
.Cells(OutRow, FINISHCOL2).Value =
DateFormat(T.finish, pjDate_mm_dd_yyyy)
.Cells(OutRow, REMWORKCOL).Value =
FormatNumber(A.RemainingWork / 60, 1)
.Cells(OutRow, PMCOL).Value = ProjPM(j)
.Cells(OutRow, ACTWRKCOL).Value =
FormatNumber(A.ActualWork / 60, 1)
.Cells(OutRow, CRITCOL).Value = strScratch
.Cells(OutRow, BASEWORKCOL).Value =
FormatNumber(A.BaselineWork / 60, 1)
.Cells(OutRow, TSCOL).Value = T.TotalSlack / 60
/ ActiveProject.HoursPerDay
End With
OutRow = OutRow + 1
End If
Next A
End If
End If
Next T
OutRowStart = OutRow
FileClose pjDoNotSave 'close the project file - done with it
Next j
Thank you
Will