Re: Issue Pulloing data from MS Project files
Code:
Sub OpenProjectCopyPasteData(MPPpathname As String)
Dim appProj As MSProject.Application
Dim aProg As MSProject.Project
Dim sel As MSProject.Selection
Dim ts As Tasks
Dim t As Task
Dim rng As Range
Dim ws As Worksheet
Dim WSName As String
Dim i As Integer
Application.DisplayAlerts = False
'
' Excel Set up to access MS Project
'
On Error Resume Next
Set appProj = GetObject(, "MSProject.Application")
If appProj Is Nothing Then
Set appProj = New MSProject.Application
End If
appProj.Visible = True
'
'Open MS Project file
'
'MsgBox "debug-OPEN:" & MPPpathname & "<"
appProj.Application.FileOpenEx MPPpathname, ReadOnly:=True
Set appProj = appProj.ActiveProject
'
'Final set up of code
'
Set projApp = Nothing
'Set aProg = appProj.Projects(MPPpathname)
appProj.Visible = True
WindowActivate WindowName:=aProg
'
' get next available project worksheet name and create the worksheet
'
'Add New Sheet
i = 0
Sheets.Add
'
'Keep looking for new name if name is in use
'
Do Until err.Number = 0
i = i + 1
WSName = "Project" & i
err.Clear
ActiveSheet.Name = WSName
Loop
Set ws = Worksheets(WSName)
'
'Copy the project columns and paste into Excel
'
Set ts = appProg.Tasks
SelectTaskColumn Column:="Project"
OutlineShowAllTasks
OutlineShowAllTasks
EditCopy
Set rng = ws.Range("A:A")
ActiveSheet.Paste Destination:=rng
SelectTaskColumn Column:="WBS"
EditCopy
Set rng = ws.Range("B:B")
ActiveSheet.Paste Destination:=rng
SelectTaskColumn Column:="Name"
EditCopy
Set rng = ws.Range("C:C")
ActiveSheet.Paste Destination:=rng
SelectTaskColumn Column:="Resource Names"
EditCopy
Set rng = ws.Range("D:D")
ActiveSheet.Paste Destination:=rng
SelectTaskColumn Column:="Duration"
EditCopy
Set rng = ws.Range("E:E")
ActiveSheet.Paste Destination:=rng
SelectTaskColumn Column:="Start"
EditCopy
Set rng = ws.Range("F:F")
ActiveSheet.Paste Destination:=rng
SelectTaskColumn Column:="Finish"
EditCopy
Set rng = ws.Range("G:G")
ActiveSheet.Paste Destination:=rng
SelectTaskColumn Column:="Baseline Start"
EditCopy
Set rng = ws.Range("H:H")
ActiveSheet.Paste Destination:=rng
SelectTaskColumn Column:="Baseline Finish"
EditCopy
Set rng = ws.Range("I:I")
ActiveSheet.Paste Destination:=rng
SelectTaskColumn Column:="Actual Start"
EditCopy
Set rng = ws.Range("J:J")
ActiveSheet.Paste Destination:=rng
SelectTaskColumn Column:="Actual Finish"
EditCopy
Set rng = ws.Range("K:K")
ActiveSheet.Paste Destination:=rng
SelectTaskColumn Column:="% Complete"
EditCopy
Set rng = ws.Range("L:L")
ActiveSheet.Paste Destination:=rng
Application.DisplayAlerts = True
appProj.DisplayAlerts = True
'
'close the project file
'
appProj.Application.ActiveProject.Close savechanges:=False
appProj.Quit
End Sub
what I find is that if a column is not inserted in view that the previous column is duplicated.
[TABLE="width: 528"]
[TR]
[TD="width: 64, bgcolor: #DFE3E8"]
WBS[/TD]
[TD="width: 64, bgcolor: #DFE3E8"]
Deliverable Name, Task Name[/TD]
[TD="width: 64, bgcolor: #DFE3E8"]
Resource Names[/TD]
[TD="width: 64, bgcolor: #DFE3E8"]
Duration[/TD]
[TD="width: 64, bgcolor: #DFE3E8"]
Start[/TD]
[TD="width: 64, bgcolor: #DFE3E8"]
Finish[/TD]
[TD="width: 64, bgcolor: #DFE3E8"]
Finish[/TD]
[TD="width: 64, bgcolor: #DFE3E8"]
Finish[/TD]
[TD="width: 64, bgcolor: #DFE3E8"]
Finish[/TD]
[TD="width: 64, bgcolor: #DFE3E8"]
Finish[/TD]
[TD="width: 64, bgcolor: #DFE3E8"]
% Complete[/TD]
[/TR]
[TR]
[TD="width: 64, bgcolor: white, align: right"]
0[/TD]
[TD="width: 64, bgcolor: white"]
LO ETO 36518 Simply SHP-FTP Migration to Axway [/TD]
[TD="width: 64, bgcolor: white"] [/TD]
[TD="width: 64, bgcolor: white"]
594 days?[/TD]
[TD="width: 64, bgcolor: white"]
Thu 9/22/16[/TD]
[TD="width: 64, bgcolor: white"]
Fri 1/25/19[/TD]
[TD="width: 64, bgcolor: white"]
Fri 1/25/19[/TD]
[TD="width: 64, bgcolor: white"]
Fri 1/25/19[/TD]
[TD="width: 64, bgcolor: white"]
Fri 1/25/19[/TD]
[TD="width: 64, bgcolor: white"]
Fri 1/25/19[/TD]
[TD="width: 64, bgcolor: white, align: right"]
51%[/TD]
[/TR]
[TR]
[TD="width: 64, bgcolor: white, align: right"]
1[/TD]
[TD="width: 64, bgcolor: white"]
Initiation Complete (Includes prerequisites)[/TD]
[TD="width: 64, bgcolor: white"] [/TD]
[TD="width: 64, bgcolor: white"]
93 days[/TD]
[TD="width: 64, bgcolor: white"]
Mon 5/14/18[/TD]
[TD="width: 64, bgcolor: white"]
Mon 9/24/18[/TD]
[TD="width: 64, bgcolor: white"]
Mon 9/24/18[/TD]
[TD="width: 64, bgcolor: white"]
Mon 9/24/18[/TD]
[TD="width: 64, bgcolor: white"]
Mon 9/24/18[/TD]
[TD="width: 64, bgcolor: white"]
Mon 9/24/18[/TD]
[TD="width: 64, bgcolor: white, align: right"]
88%[/TD]
[/TR]
[/TABLE]