The following code yields run time error 91 with the message: " Object Variable or With block variable not set".
Private Sub CommandButton1_Click()
Dim appProj As MSProject.Application
Dim t As Task
Dim myProject As MSProject.Project
Dim tCol, sCol As Integer '******** Source Path Start Column ********
Dim Qual_File_Name As Variant
sCol = 12
'AppActivate "Microsoft Excel"
With Worksheets("Sheet1")
'--------- Construct the Fully Qualified Source FIle Name in Var Qual_
Qual_File_Name = _
.Cells(2, sCol) & "" & _
.Cells(3, sCol) & "" & _
.Cells(4, sCol) & "" & _
.Cells(5, sCol) & "" & _
.Cells(6, sCol) & "" & _
.Cells(7, sCol)
End With
'Qual_File_Name = Qual_File_Name
'MsgBox Qual_File_Name
'========= Create Object ==========
Set appProj = CreateObject("Msproject.Application")
'========= Open MSP File ==========
'appProj.FileOpen "C:\@Z686669\01 - Projects\02 - DRM\04 - Project Plans\Wireless DRM Transition - FRPA - 12112017 V1T.mpp"
appProj.FileOpen Qual_File_Name
'========= Set Active Project =========
Set myProject = appProj.ActiveProject
With Worksheets("Sheet2")
For Each t In myProject.Tasks
MsgBox t.ID
.Cells(1, 1).Value = t.ID
.Cells(2, 2).Value = t.Name
.Cells(3, 3).Value = t.Start
.Cells(4, 4).Value = t.Finish
Next t
End With
End Sub
The code stops at:
Not sure what is wrong here. Definitions and instantiation seem to be as should be, to me. A prompt response shall be greatly appreciated!
thanks & regards,
Private Sub CommandButton1_Click()
Dim appProj As MSProject.Application
Dim t As Task
Dim myProject As MSProject.Project
Dim tCol, sCol As Integer '******** Source Path Start Column ********
Dim Qual_File_Name As Variant
sCol = 12
'AppActivate "Microsoft Excel"
With Worksheets("Sheet1")
'--------- Construct the Fully Qualified Source FIle Name in Var Qual_
Qual_File_Name = _
.Cells(2, sCol) & "" & _
.Cells(3, sCol) & "" & _
.Cells(4, sCol) & "" & _
.Cells(5, sCol) & "" & _
.Cells(6, sCol) & "" & _
.Cells(7, sCol)
End With
'Qual_File_Name = Qual_File_Name
'MsgBox Qual_File_Name
'========= Create Object ==========
Set appProj = CreateObject("Msproject.Application")
'========= Open MSP File ==========
'appProj.FileOpen "C:\@Z686669\01 - Projects\02 - DRM\04 - Project Plans\Wireless DRM Transition - FRPA - 12112017 V1T.mpp"
appProj.FileOpen Qual_File_Name
'========= Set Active Project =========
Set myProject = appProj.ActiveProject
With Worksheets("Sheet2")
For Each t In myProject.Tasks
MsgBox t.ID
.Cells(1, 1).Value = t.ID
.Cells(2, 2).Value = t.Name
.Cells(3, 3).Value = t.Start
.Cells(4, 4).Value = t.Finish
Next t
End With
End Sub
The code stops at:
- MsgBox t.ID
Not sure what is wrong here. Definitions and instantiation seem to be as should be, to me. A prompt response shall be greatly appreciated!
thanks & regards,