MS Project - Excel -Getting Run Time Error - 91

Anwer

New Member
Joined
Jun 12, 2007
Messages
24
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:


  • 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,
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
it sounds like t is not gettings assigned.
is myProject.Tasks.count > 0
is t.ID an actual property?
 
Upvote 0
Yes, myProject.Tasks.count has 262 value. I will check if in the newer version .ID property has been renamed. I did not think of that.

thank you
 
Upvote 0
ID is a defined property. So are Name, Start and Finish. But that part of the code is never reached. It abends on first reference of t.ID.
 
Upvote 0

Forum statistics

Threads
1,215,436
Messages
6,124,869
Members
449,192
Latest member
MoonDancer

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top