Not sure what happened….. it ended up working perfectly… exactly the way I
thought it would work the first time when it did not work. Below is the code
so far in case anyone finds it helpful….. or wants to comment.
Thanks again for taking the time.....
Option Explicit
Dim oRow As Row
Dim oCell As Cell
Dim sCellText As String
Dim i As Integer
Dim C As Integer
Dim Pop As Integer
Dim x As String
Dim Y As Integer
Dim Dev As Variant
Dim DentLevel As Integer
Dim ColOne(1 To 200) As String
Dim ColTwo(1 To 200) As String
Dim ColThree(1 To 200) As String
Dim ColFour(1 To 200) As String
Dim ColFive(1 To 200) As String
Dim ColSix(1 To 200) As String
Dim T As Task
Dim pjApp As MSProject.Application
Dim myProj As MSProject.Project
Sub RetrieveTableItems()
On Error GoTo ErrorHandler
i = 1
' Loop through each row in the table.
For Each oRow In ActiveDocument.Tables(1).Rows 'Index # finds the Table
in question
C = 0
For Each oCell In oRow.Cells ' Loop through each cell in the
current row.
If C = 0 Then
ColOne(i) = oCell.Range
ElseIf C = 1 Then
ColTwo(i) = oCell.Range
ElseIf C = 2 Then
ColThree(i) = oCell.Range
ElseIf C = 3 Then
ColFour(i) = oCell.Range
ElseIf C = 4 Then
ColFive(i) = oCell.Range
ElseIf C = 5 Then
ColSix(i) = oCell.Range
End If
C = C + 1
Next oCell
C = 7
i = i + 1
Next oRow
ErrorHandler:
If Err <> 0 Then
Dim Msg As String
Msg = "Error # " & Str(Err.Number) & Chr(13) & Err.Description _
& Chr(13) & "Make sure there is a table in the current document."
MsgBox Msg, , "Error"
End If
OpenProject
MakeMpp
End Sub
Sub CleanCol()
If Left(x, 1) = Chr(12) Then
x = Right(x, Len(x) - 1)
End If
If Right(x, 1) = Chr(12) Then
x = Left(x, Len(x) - 1)
End If
'************************************
If Left(x, 1) = Chr(13) Then
x = Right(x, Len(x) - 1)
End If
If Right(x, 1) = Chr(13) Then
x = Left(x, Len(x) - 1)
End If
'************************************
If Left(x, 1) = Chr(7) Then
x = Right(x, Len(x) - 1)
End If
If Right(x, 1) = Chr(7) Then
x = Left(x, Len(x) - 1)
End If
'************************************
'************************************
If Left(x, 1) = Chr(12) Then
x = Right(x, Len(x) - 1)
End If
If Right(x, 1) = Chr(12) Then
x = Left(x, Len(x) - 1)
End If
'************************************
If Left(x, 1) = Chr(13) Then
x = Right(x, Len(x) - 1)
End If
If Right(x, 1) = Chr(13) Then
x = Left(x, Len(x) - 1)
End If
'************************************
If Left(x, 1) = Chr(7) Then
x = Right(x, Len(x) - 1)
End If
If Right(x, 1) = Chr(7) Then
x = Left(x, Len(x) - 1)
End If
'************************************
End Sub
Sub MakeMpp()
myProj.Tasks.Add ("Phase 1")
Font Bold:=True
DentLevel = 1
Y = Y + 1
For Pop = 2 To 200
x = ColTwo(Pop)
CleanCol
If Not x = "" Then
x = ColOne(Pop)
CleanCol
myProj.Tasks.Add (x)
Y = Y + 1
SelectRow Row:=Y, rowrelative:=False
Font Color:=pjBlue
Font Bold:=False
If DentLevel = 1 Then
OutlineIndent
End If
DentLevel = 2
End If
Next Pop
'**************************************
myProj.Tasks.Add ("Phase 2")
Y = Y + 1
SelectRow Row:=Y, rowrelative:=False
Font Bold:=True
OutlineOutdent
DentLevel = 1
For Pop = 2 To 200
x = ColTwo(Pop)
CleanCol
If Not x = "" Then
x = ColOne(Pop)
CleanCol
myProj.Tasks.Add (x)
Y = Y + 1
SelectRow Row:=Y, rowrelative:=False
Font Color:=pjBlue
Font Bold:=False
If DentLevel = 1 Then
OutlineIndent
End If
DentLevel = 2
End If
Next Pop
'**************************************
myProj.Tasks.Add ("Phase 3")
Y = Y + 1
SelectRow Row:=Y, rowrelative:=False
Font Bold:=True
OutlineOutdent
DentLevel = 1
For Pop = 2 To 200
x = ColFour(Pop)
CleanCol
If Not x = "" Then
x = ColOne(Pop)
CleanCol
myProj.Tasks.Add (x)
Y = Y + 1
SelectRow Row:=Y, rowrelative:=False
Font Color:=pjBlue
Font Bold:=False
If DentLevel = 1 Then
OutlineIndent
End If
DentLevel = 2
End If
Next Pop
'**************************************
myProj.Tasks.Add ("Phase 4")
Y = Y + 1
SelectRow Row:=Y, rowrelative:=False
Font Bold:=True
OutlineOutdent
DentLevel = 1
For Pop = 2 To 200
x = ColFive(Pop)
CleanCol
If Not x = "" Then
x = ColOne(Pop)
CleanCol
myProj.Tasks.Add (x)
Y = Y + 1
SelectRow Row:=Y, rowrelative:=False
Font Color:=pjBlue
Font Bold:=False
If DentLevel = 1 Then
OutlineIndent
End If
DentLevel = 2
End If
Next Pop
'**************************************
myProj.Tasks.Add ("Phase 5")
Y = Y + 1
SelectRow Row:=Y, rowrelative:=False
Font Bold:=True
OutlineOutdent
DentLevel = 1
For Pop = 2 To 200
x = ColSix(Pop)
CleanCol
If Not x = "" Then
x = ColOne(Pop)
CleanCol
myProj.Tasks.Add (x)
Y = Y + 1
SelectRow Row:=Y, rowrelative:=False
Font Color:=pjBlue
Font Bold:=False
If DentLevel = 1 Then
OutlineIndent
End If
DentLevel = 2
End If
Next Pop
'**************************************
End Sub
Sub OpenProject()
Set pjApp = New MSProject.Application
pjApp.Visible = True
Set myProj = pjApp.Projects.Add
pjApp.ScreenUpdating = False
End Sub