Code changes for inserted projects

K

Kevin Newman

I have a master project that used to consist of subprojects as ile items
within the same file. Hence I could use the following in my VB coding:

"For Each tsk In ActiveProject.Tasks"

Now, in place of these line items, the subprojects are actually inserted
projects that use resources from the same pool and my code bombs. I get the
error <Object variable or With block variable not set> when I open the macro
in debug mode.

What do I need to do to get it working again?

I need to run a report weekly that shows the resource usage across all
projects within the master project by month
 
J

John

Kevin Newman said:
I have a master project that used to consist of subprojects as ile items
within the same file. Hence I could use the following in my VB coding:

"For Each tsk In ActiveProject.Tasks"

Now, in place of these line items, the subprojects are actually inserted
projects that use resources from the same pool and my code bombs. I get the
error <Object variable or With block variable not set> when I open the macro
in debug mode.

What do I need to do to get it working again?

I need to run a report weekly that shows the resource usage across all
projects within the master project by month

Kevin,
I'm not sure why your code bombs, I would expect it to not give what you
want but otherwise it should run ok. The error message sounds like the
code is trying to refer to an object that isn't defined.

Nonetheless, when working with consolidated projects a different tack is
needed to cycle through all the tasks. Remember, the subtasks of the
inserted projects are NOT part of the master because the subproject are
not part of the master - they are only inserted via a pointer. Here is a
looping structure you can use to look at all tasks in a master. The
first line insures the master is "exploded":

OutlineShowTasks expandinsertedprojects:=True
SelectTaskColumn
Set Area = ActiveSelection.Tasks
For Each t in Area
[your code here]
Next t

Hope this helps.
John
Project MVP
 
K

Kevin Newman

Thanks John. I'll give it a try.

John said:
Kevin Newman said:
I have a master project that used to consist of subprojects as ile items
within the same file. Hence I could use the following in my VB coding:

"For Each tsk In ActiveProject.Tasks"

Now, in place of these line items, the subprojects are actually inserted
projects that use resources from the same pool and my code bombs. I get the
error <Object variable or With block variable not set> when I open the macro
in debug mode.

What do I need to do to get it working again?

I need to run a report weekly that shows the resource usage across all
projects within the master project by month

Kevin,
I'm not sure why your code bombs, I would expect it to not give what you
want but otherwise it should run ok. The error message sounds like the
code is trying to refer to an object that isn't defined.

Nonetheless, when working with consolidated projects a different tack is
needed to cycle through all the tasks. Remember, the subtasks of the
inserted projects are NOT part of the master because the subproject are
not part of the master - they are only inserted via a pointer. Here is a
looping structure you can use to look at all tasks in a master. The
first line insures the master is "exploded":

OutlineShowTasks expandinsertedprojects:=True
SelectTaskColumn
Set Area = ActiveSelection.Tasks
For Each t in Area
[your code here]
Next t

Hope this helps.
John
Project MVP
 
K

Kevin Newman

John,

I could get that code to work if I wanted some values from task fields, but
it wouldn't give me the resource values I am looking for. Here is the full
code for the macro I am trying to run. This is using my code not your
suggestion.

***************************************************

Sub WKCT_Load()
Dim tsk As Task
Dim tsv As TimeScaleValues, hmany As Long, HoursPerDay As String, hdr As
String
Dim strt, fnsh, seldt, badID
hdr = "Category;Resource Group;Job;Date;Hours"
' sets report start and finish dates based on current date
Select Case Format(Date, "mm")
Case 1 To 11
Select Case Format(Date, "dd")
Case 1 To 24
strt = Format(Date, "mm") & "/1/" & Format(Date, "yyyy")
Case 25 To 31
strt = Format(Date, "mm") + 1 & "/1/" & Format(Date, "yyyy")
End Select
Case 12
Select Case Format(Date, "dd")
Case 1 To 24
strt = Format(Date, "mm") & "/1/" & Format(Date, "yyyy")
Case 25 To 31
strt = Format(Date, "mm") + 1 & "/1/" & Format(Date, "yyyy") + 1
End Select
End Select
Select Case Format(Date, "mm")
'if month is prior to September then Finish Date defaults to end of this
fiscal year
Case 1 To 8
fnsh = "03/31/" & Format(Date, "yyyy") + 1
'if month is September or later then Finish Date defaults to end of next
fiscal year
Case 9 To 12
fnsh = "03/31/" & Format(Date, "yyyy") + 2
End Select
' opens text file for output
Open "c:\data\text\WorkCtr.txt" For Output As #2
Print #2, hdr ' prints header information
'generate report
For Each tsk In ActiveProject.Tasks
If tsk.ResourceGroup = "" Or tsk.ResourceNames = "103300" Or
tsk.ResourceNames = "P-103300" Then
Else
Set tsv = tsk.TimeScaleData(strt, fnsh, TimescaleUnit:=pjTimescaleDays)
For hmany = 1 To tsv.Count
badID = tsk.ID
If tsv(hmany).Value = "" Then
Else
Print #2, tsk.Text3 & ";" & tsk.ResourceGroup & ";" & tsk.Text1
& ";" & Format$(tsv(hmany).StartDate, "mm/1/yy") & ";" & tsv(hmany).Value / 60
End If
Next hmany
'StatusBar True, "Outputing Records"
End If
Next tsk
Close #2
'open Excel and create pivot table
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open "C:\Documents and Settings\knewman\Application
Data\Microsoft\Excel\XLStart\PERSONAL.XLS"
XL.Visible = False
XL.Application.Run "PERSONAL.XLS!Project_Data.Work_Center_Load" '
creates table
XL.Application.Run "PERSONAL.XLS!Module15.wchtml" ' creates web page
XL.Application.Quit
Set XL = Nothing
End Sub

**********************************************

I tried replacing my "For Each tsk In ActiveProject.Tasks.....Next tsk"
statement with your code but I got the same result.

In either case the "If tsk.ResourceGroup = "" Or tsk.ResourceNames =
"103300" Or tsk.ResourceNames = "P-103300" Then" statement is where it bombs.

Any help would be appreciated.

Kevin

John said:
Kevin Newman said:
I have a master project that used to consist of subprojects as ile items
within the same file. Hence I could use the following in my VB coding:

"For Each tsk In ActiveProject.Tasks"

Now, in place of these line items, the subprojects are actually inserted
projects that use resources from the same pool and my code bombs. I get the
error <Object variable or With block variable not set> when I open the macro
in debug mode.

What do I need to do to get it working again?

I need to run a report weekly that shows the resource usage across all
projects within the master project by month

Kevin,
I'm not sure why your code bombs, I would expect it to not give what you
want but otherwise it should run ok. The error message sounds like the
code is trying to refer to an object that isn't defined.

Nonetheless, when working with consolidated projects a different tack is
needed to cycle through all the tasks. Remember, the subtasks of the
inserted projects are NOT part of the master because the subproject are
not part of the master - they are only inserted via a pointer. Here is a
looping structure you can use to look at all tasks in a master. The
first line insures the master is "exploded":

OutlineShowTasks expandinsertedprojects:=True
SelectTaskColumn
Set Area = ActiveSelection.Tasks
For Each t in Area
[your code here]
Next t

Hope this helps.
John
Project MVP
 
J

JackD

Right after the "for each" loop starts insert the following "if...then"
capturing all the code between for each and next.

if not tsk is nothing then
'put the rest of the code here
end if

Looks like you are simply running into a blank line in the project.
--
-Jack ... For Microsoft Project information and macro examples visit
http://masamiki.com/project
or http://zo-d.com/blog/index.html
..
Kevin Newman said:
John,

I could get that code to work if I wanted some values from task fields, but
it wouldn't give me the resource values I am looking for. Here is the full
code for the macro I am trying to run. This is using my code not your
suggestion.

***************************************************

Sub WKCT_Load()
Dim tsk As Task
Dim tsv As TimeScaleValues, hmany As Long, HoursPerDay As String, hdr As
String
Dim strt, fnsh, seldt, badID
hdr = "Category;Resource Group;Job;Date;Hours"
' sets report start and finish dates based on current date
Select Case Format(Date, "mm")
Case 1 To 11
Select Case Format(Date, "dd")
Case 1 To 24
strt = Format(Date, "mm") & "/1/" & Format(Date, "yyyy")
Case 25 To 31
strt = Format(Date, "mm") + 1 & "/1/" & Format(Date, "yyyy")
End Select
Case 12
Select Case Format(Date, "dd")
Case 1 To 24
strt = Format(Date, "mm") & "/1/" & Format(Date, "yyyy")
Case 25 To 31
strt = Format(Date, "mm") + 1 & "/1/" & Format(Date, "yyyy") + 1
End Select
End Select
Select Case Format(Date, "mm")
'if month is prior to September then Finish Date defaults to end of this
fiscal year
Case 1 To 8
fnsh = "03/31/" & Format(Date, "yyyy") + 1
'if month is September or later then Finish Date defaults to end of next
fiscal year
Case 9 To 12
fnsh = "03/31/" & Format(Date, "yyyy") + 2
End Select
' opens text file for output
Open "c:\data\text\WorkCtr.txt" For Output As #2
Print #2, hdr ' prints header information
'generate report
For Each tsk In ActiveProject.Tasks
If tsk.ResourceGroup = "" Or tsk.ResourceNames = "103300" Or
tsk.ResourceNames = "P-103300" Then
Else
Set tsv = tsk.TimeScaleData(strt, fnsh, TimescaleUnit:=pjTimescaleDays)
For hmany = 1 To tsv.Count
badID = tsk.ID
If tsv(hmany).Value = "" Then
Else
Print #2, tsk.Text3 & ";" & tsk.ResourceGroup & ";" & tsk.Text1
& ";" & Format$(tsv(hmany).StartDate, "mm/1/yy") & ";" & tsv(hmany).Value / 60
End If
Next hmany
'StatusBar True, "Outputing Records"
End If
Next tsk
Close #2
'open Excel and create pivot table
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open "C:\Documents and Settings\knewman\Application
Data\Microsoft\Excel\XLStart\PERSONAL.XLS"
XL.Visible = False
XL.Application.Run "PERSONAL.XLS!Project_Data.Work_Center_Load" '
creates table
XL.Application.Run "PERSONAL.XLS!Module15.wchtml" ' creates web page
XL.Application.Quit
Set XL = Nothing
End Sub

**********************************************

I tried replacing my "For Each tsk In ActiveProject.Tasks.....Next tsk"
statement with your code but I got the same result.

In either case the "If tsk.ResourceGroup = "" Or tsk.ResourceNames =
"103300" Or tsk.ResourceNames = "P-103300" Then" statement is where it bombs.

Any help would be appreciated.

Kevin

John said:
Kevin Newman said:
I have a master project that used to consist of subprojects as ile items
within the same file. Hence I could use the following in my VB coding:

"For Each tsk In ActiveProject.Tasks"

Now, in place of these line items, the subprojects are actually inserted
projects that use resources from the same pool and my code bombs. I get the
error <Object variable or With block variable not set> when I open the macro
in debug mode.

What do I need to do to get it working again?

I need to run a report weekly that shows the resource usage across all
projects within the master project by month

Kevin,
I'm not sure why your code bombs, I would expect it to not give what you
want but otherwise it should run ok. The error message sounds like the
code is trying to refer to an object that isn't defined.

Nonetheless, when working with consolidated projects a different tack is
needed to cycle through all the tasks. Remember, the subtasks of the
inserted projects are NOT part of the master because the subproject are
not part of the master - they are only inserted via a pointer. Here is a
looping structure you can use to look at all tasks in a master. The
first line insures the master is "exploded":

OutlineShowTasks expandinsertedprojects:=True
SelectTaskColumn
Set Area = ActiveSelection.Tasks
For Each t in Area
[your code here]
Next t

Hope this helps.
John
Project MVP
 
R

Ray McCoppin

If you are working with a master project you need to loop thru each
subproject in the master project. Like this

For Each subp In ActiveProject.Subprojects
For Each tsk In subp.Tasks
 
J

John

Kevin Newman said:
John,

I could get that code to work if I wanted some values from task fields, but
it wouldn't give me the resource values I am looking for. Here is the full
code for the macro I am trying to run. This is using my code not your
suggestion.

***************************************************

Sub WKCT_Load()
Dim tsk As Task
Dim tsv As TimeScaleValues, hmany As Long, HoursPerDay As String, hdr As
String
Dim strt, fnsh, seldt, badID
hdr = "Category;Resource Group;Job;Date;Hours"
' sets report start and finish dates based on current date
Select Case Format(Date, "mm")
Case 1 To 11
Select Case Format(Date, "dd")
Case 1 To 24
strt = Format(Date, "mm") & "/1/" & Format(Date, "yyyy")
Case 25 To 31
strt = Format(Date, "mm") + 1 & "/1/" & Format(Date, "yyyy")
End Select
Case 12
Select Case Format(Date, "dd")
Case 1 To 24
strt = Format(Date, "mm") & "/1/" & Format(Date, "yyyy")
Case 25 To 31
strt = Format(Date, "mm") + 1 & "/1/" & Format(Date, "yyyy") + 1
End Select
End Select
Select Case Format(Date, "mm")
'if month is prior to September then Finish Date defaults to end of this
fiscal year
Case 1 To 8
fnsh = "03/31/" & Format(Date, "yyyy") + 1
'if month is September or later then Finish Date defaults to end of next
fiscal year
Case 9 To 12
fnsh = "03/31/" & Format(Date, "yyyy") + 2
End Select
' opens text file for output
Open "c:\data\text\WorkCtr.txt" For Output As #2
Print #2, hdr ' prints header information
'generate report
For Each tsk In ActiveProject.Tasks
If tsk.ResourceGroup = "" Or tsk.ResourceNames = "103300" Or
tsk.ResourceNames = "P-103300" Then
Else
Set tsv = tsk.TimeScaleData(strt, fnsh, TimescaleUnit:=pjTimescaleDays)
For hmany = 1 To tsv.Count
badID = tsk.ID
If tsv(hmany).Value = "" Then
Else
Print #2, tsk.Text3 & ";" & tsk.ResourceGroup & ";" & tsk.Text1
& ";" & Format$(tsv(hmany).StartDate, "mm/1/yy") & ";" & tsv(hmany).Value /
60
End If
Next hmany
'StatusBar True, "Outputing Records"
End If
Next tsk
Close #2
'open Excel and create pivot table
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open "C:\Documents and Settings\knewman\Application
Data\Microsoft\Excel\XLStart\PERSONAL.XLS"
XL.Visible = False
XL.Application.Run "PERSONAL.XLS!Project_Data.Work_Center_Load" '
creates table
XL.Application.Run "PERSONAL.XLS!Module15.wchtml" ' creates web page
XL.Application.Quit
Set XL = Nothing
End Sub

**********************************************

I tried replacing my "For Each tsk In ActiveProject.Tasks.....Next tsk"
statement with your code but I got the same result.

In either case the "If tsk.ResourceGroup = "" Or tsk.ResourceNames =
"103300" Or tsk.ResourceNames = "P-103300" Then" statement is where it bombs.

Any help would be appreciated.

Kevin

John said:
Kevin Newman said:
I have a master project that used to consist of subprojects as ile items
within the same file. Hence I could use the following in my VB coding:

"For Each tsk In ActiveProject.Tasks"

Now, in place of these line items, the subprojects are actually inserted
projects that use resources from the same pool and my code bombs. I get
the
error <Object variable or With block variable not set> when I open the
macro
in debug mode.

What do I need to do to get it working again?

I need to run a report weekly that shows the resource usage across all
projects within the master project by month

Kevin,
I'm not sure why your code bombs, I would expect it to not give what you
want but otherwise it should run ok. The error message sounds like the
code is trying to refer to an object that isn't defined.

Nonetheless, when working with consolidated projects a different tack is
needed to cycle through all the tasks. Remember, the subtasks of the
inserted projects are NOT part of the master because the subproject are
not part of the master - they are only inserted via a pointer. Here is a
looping structure you can use to look at all tasks in a master. The
first line insures the master is "exploded":

OutlineShowTasks expandinsertedprojects:=True
SelectTaskColumn
Set Area = ActiveSelection.Tasks
For Each t in Area
[your code here]
Next t

Hope this helps.
John
Project MVP

Kevin,
Actually the code structure I suggested can still be used for resource
information since at the task level, resources are assignments. In that
case an inner loop might look something like:
For Each A in t.Assignments
[capture the assignment timescale values]
Next A

Nonetheless, I see Jack also chimed in with a suggestion. Did that help?

John
Project MVP
 
K

Kevin Newman

Jack,

You were partially right. I did find some blank lines. Once I fixed that I
discovered another issue. The process was stopping at activities that were
actually external predecessors and successors. I turned those off in
Tools/Options/View and the code ran all the way to completion.

Thank you for the help.

JackD said:
Right after the "for each" loop starts insert the following "if...then"
capturing all the code between for each and next.

if not tsk is nothing then
'put the rest of the code here
end if

Looks like you are simply running into a blank line in the project.
--
-Jack ... For Microsoft Project information and macro examples visit
http://masamiki.com/project
or http://zo-d.com/blog/index.html
..
Kevin Newman said:
John,

I could get that code to work if I wanted some values from task fields, but
it wouldn't give me the resource values I am looking for. Here is the full
code for the macro I am trying to run. This is using my code not your
suggestion.

***************************************************

Sub WKCT_Load()
Dim tsk As Task
Dim tsv As TimeScaleValues, hmany As Long, HoursPerDay As String, hdr As
String
Dim strt, fnsh, seldt, badID
hdr = "Category;Resource Group;Job;Date;Hours"
' sets report start and finish dates based on current date
Select Case Format(Date, "mm")
Case 1 To 11
Select Case Format(Date, "dd")
Case 1 To 24
strt = Format(Date, "mm") & "/1/" & Format(Date, "yyyy")
Case 25 To 31
strt = Format(Date, "mm") + 1 & "/1/" & Format(Date, "yyyy")
End Select
Case 12
Select Case Format(Date, "dd")
Case 1 To 24
strt = Format(Date, "mm") & "/1/" & Format(Date, "yyyy")
Case 25 To 31
strt = Format(Date, "mm") + 1 & "/1/" & Format(Date, "yyyy") + 1
End Select
End Select
Select Case Format(Date, "mm")
'if month is prior to September then Finish Date defaults to end of this
fiscal year
Case 1 To 8
fnsh = "03/31/" & Format(Date, "yyyy") + 1
'if month is September or later then Finish Date defaults to end of next
fiscal year
Case 9 To 12
fnsh = "03/31/" & Format(Date, "yyyy") + 2
End Select
' opens text file for output
Open "c:\data\text\WorkCtr.txt" For Output As #2
Print #2, hdr ' prints header information
'generate report
For Each tsk In ActiveProject.Tasks
If tsk.ResourceGroup = "" Or tsk.ResourceNames = "103300" Or
tsk.ResourceNames = "P-103300" Then
Else
Set tsv = tsk.TimeScaleData(strt, fnsh, TimescaleUnit:=pjTimescaleDays)
For hmany = 1 To tsv.Count
badID = tsk.ID
If tsv(hmany).Value = "" Then
Else
Print #2, tsk.Text3 & ";" & tsk.ResourceGroup & ";" & tsk.Text1
& ";" & Format$(tsv(hmany).StartDate, "mm/1/yy") & ";" & tsv(hmany).Value / 60
End If
Next hmany
'StatusBar True, "Outputing Records"
End If
Next tsk
Close #2
'open Excel and create pivot table
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open "C:\Documents and Settings\knewman\Application
Data\Microsoft\Excel\XLStart\PERSONAL.XLS"
XL.Visible = False
XL.Application.Run "PERSONAL.XLS!Project_Data.Work_Center_Load" '
creates table
XL.Application.Run "PERSONAL.XLS!Module15.wchtml" ' creates web page
XL.Application.Quit
Set XL = Nothing
End Sub

**********************************************

I tried replacing my "For Each tsk In ActiveProject.Tasks.....Next tsk"
statement with your code but I got the same result.

In either case the "If tsk.ResourceGroup = "" Or tsk.ResourceNames =
"103300" Or tsk.ResourceNames = "P-103300" Then" statement is where it bombs.

Any help would be appreciated.

Kevin

John said:
I have a master project that used to consist of subprojects as ile items
within the same file. Hence I could use the following in my VB coding:

"For Each tsk In ActiveProject.Tasks"

Now, in place of these line items, the subprojects are actually inserted
projects that use resources from the same pool and my code bombs. I get the
error <Object variable or With block variable not set> when I open the macro
in debug mode.

What do I need to do to get it working again?

I need to run a report weekly that shows the resource usage across all
projects within the master project by month

Kevin,
I'm not sure why your code bombs, I would expect it to not give what you
want but otherwise it should run ok. The error message sounds like the
code is trying to refer to an object that isn't defined.

Nonetheless, when working with consolidated projects a different tack is
needed to cycle through all the tasks. Remember, the subtasks of the
inserted projects are NOT part of the master because the subproject are
not part of the master - they are only inserted via a pointer. Here is a
looping structure you can use to look at all tasks in a master. The
first line insures the master is "exploded":

OutlineShowTasks expandinsertedprojects:=True
SelectTaskColumn
Set Area = ActiveSelection.Tasks
For Each t in Area
[your code here]
Next t

Hope this helps.
John
Project MVP
 
K

Kevin Newman

John,

I have implemented both your's and Jack's suggestions as they both were
needed to fix the problem. Check out my reply to Jack for an additional issue
that arose.

Thank you again for your help.

John said:
Kevin Newman said:
John,

I could get that code to work if I wanted some values from task fields, but
it wouldn't give me the resource values I am looking for. Here is the full
code for the macro I am trying to run. This is using my code not your
suggestion.

***************************************************

Sub WKCT_Load()
Dim tsk As Task
Dim tsv As TimeScaleValues, hmany As Long, HoursPerDay As String, hdr As
String
Dim strt, fnsh, seldt, badID
hdr = "Category;Resource Group;Job;Date;Hours"
' sets report start and finish dates based on current date
Select Case Format(Date, "mm")
Case 1 To 11
Select Case Format(Date, "dd")
Case 1 To 24
strt = Format(Date, "mm") & "/1/" & Format(Date, "yyyy")
Case 25 To 31
strt = Format(Date, "mm") + 1 & "/1/" & Format(Date, "yyyy")
End Select
Case 12
Select Case Format(Date, "dd")
Case 1 To 24
strt = Format(Date, "mm") & "/1/" & Format(Date, "yyyy")
Case 25 To 31
strt = Format(Date, "mm") + 1 & "/1/" & Format(Date, "yyyy") + 1
End Select
End Select
Select Case Format(Date, "mm")
'if month is prior to September then Finish Date defaults to end of this
fiscal year
Case 1 To 8
fnsh = "03/31/" & Format(Date, "yyyy") + 1
'if month is September or later then Finish Date defaults to end of next
fiscal year
Case 9 To 12
fnsh = "03/31/" & Format(Date, "yyyy") + 2
End Select
' opens text file for output
Open "c:\data\text\WorkCtr.txt" For Output As #2
Print #2, hdr ' prints header information
'generate report
For Each tsk In ActiveProject.Tasks
If tsk.ResourceGroup = "" Or tsk.ResourceNames = "103300" Or
tsk.ResourceNames = "P-103300" Then
Else
Set tsv = tsk.TimeScaleData(strt, fnsh, TimescaleUnit:=pjTimescaleDays)
For hmany = 1 To tsv.Count
badID = tsk.ID
If tsv(hmany).Value = "" Then
Else
Print #2, tsk.Text3 & ";" & tsk.ResourceGroup & ";" & tsk.Text1
& ";" & Format$(tsv(hmany).StartDate, "mm/1/yy") & ";" & tsv(hmany).Value /
60
End If
Next hmany
'StatusBar True, "Outputing Records"
End If
Next tsk
Close #2
'open Excel and create pivot table
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open "C:\Documents and Settings\knewman\Application
Data\Microsoft\Excel\XLStart\PERSONAL.XLS"
XL.Visible = False
XL.Application.Run "PERSONAL.XLS!Project_Data.Work_Center_Load" '
creates table
XL.Application.Run "PERSONAL.XLS!Module15.wchtml" ' creates web page
XL.Application.Quit
Set XL = Nothing
End Sub

**********************************************

I tried replacing my "For Each tsk In ActiveProject.Tasks.....Next tsk"
statement with your code but I got the same result.

In either case the "If tsk.ResourceGroup = "" Or tsk.ResourceNames =
"103300" Or tsk.ResourceNames = "P-103300" Then" statement is where it bombs.

Any help would be appreciated.

Kevin

John said:
I have a master project that used to consist of subprojects as ile items
within the same file. Hence I could use the following in my VB coding:

"For Each tsk In ActiveProject.Tasks"

Now, in place of these line items, the subprojects are actually inserted
projects that use resources from the same pool and my code bombs. I get
the
error <Object variable or With block variable not set> when I open the
macro
in debug mode.

What do I need to do to get it working again?

I need to run a report weekly that shows the resource usage across all
projects within the master project by month

Kevin,
I'm not sure why your code bombs, I would expect it to not give what you
want but otherwise it should run ok. The error message sounds like the
code is trying to refer to an object that isn't defined.

Nonetheless, when working with consolidated projects a different tack is
needed to cycle through all the tasks. Remember, the subtasks of the
inserted projects are NOT part of the master because the subproject are
not part of the master - they are only inserted via a pointer. Here is a
looping structure you can use to look at all tasks in a master. The
first line insures the master is "exploded":

OutlineShowTasks expandinsertedprojects:=True
SelectTaskColumn
Set Area = ActiveSelection.Tasks
For Each t in Area
[your code here]
Next t

Hope this helps.
John
Project MVP

Kevin,
Actually the code structure I suggested can still be used for resource
information since at the task level, resources are assignments. In that
case an inner loop might look something like:
For Each A in t.Assignments
[capture the assignment timescale values]
Next A

Nonetheless, I see Jack also chimed in with a suggestion. Did that help?

John
Project MVP
 
J

Jan De Messemaeker

Hi,

Better try this

for each subp in activeproject.subprojects
set insertedp=subp.sourceproject
for each job in insertedp.tasks

HTH
 
K

Kevin Newman

Thanks Jan. I have already solved my problem, but this looks llike it will
run faster.
 
J

John

Kevin Newman said:
John,

I have implemented both your's and Jack's suggestions as they both were
needed to fix the problem. Check out my reply to Jack for an additional issue
that arose.

Thank you again for your help.


Kevin,
Just like with changing light bulbs, sometimes it takes more than one
MVP to solve a problem. I'm glad you got things working.

You're welcome and thanks for the feedback.

John
 
J

JackD

Kevin,

I usually use some nested if statements to handle this. First start with:

if not task is nothing then

often I eliminate summary tasks

if not task.summary then

and in your case you would eliminate external tasks using

if not task.ExternalTask then

The last line is going to be more effective than turning things off in a
particular view.

--
-Jack ... For Microsoft Project information and macro examples visit
http://masamiki.com/project
or http://zo-d.com/blog/index.html
..
Kevin Newman said:
Jack,

You were partially right. I did find some blank lines. Once I fixed that I
discovered another issue. The process was stopping at activities that were
actually external predecessors and successors. I turned those off in
Tools/Options/View and the code ran all the way to completion.

Thank you for the help.

JackD said:
Right after the "for each" loop starts insert the following "if...then"
capturing all the code between for each and next.

if not tsk is nothing then
'put the rest of the code here
end if

Looks like you are simply running into a blank line in the project.
--
-Jack ... For Microsoft Project information and macro examples visit
http://masamiki.com/project
or http://zo-d.com/blog/index.html
..
Kevin Newman said:
John,

I could get that code to work if I wanted some values from task
fields,
but
it wouldn't give me the resource values I am looking for. Here is the full
code for the macro I am trying to run. This is using my code not your
suggestion.

***************************************************

Sub WKCT_Load()
Dim tsk As Task
Dim tsv As TimeScaleValues, hmany As Long, HoursPerDay As String, hdr As
String
Dim strt, fnsh, seldt, badID
hdr = "Category;Resource Group;Job;Date;Hours"
' sets report start and finish dates based on current date
Select Case Format(Date, "mm")
Case 1 To 11
Select Case Format(Date, "dd")
Case 1 To 24
strt = Format(Date, "mm") & "/1/" & Format(Date, "yyyy")
Case 25 To 31
strt = Format(Date, "mm") + 1 & "/1/" & Format(Date, "yyyy")
End Select
Case 12
Select Case Format(Date, "dd")
Case 1 To 24
strt = Format(Date, "mm") & "/1/" & Format(Date, "yyyy")
Case 25 To 31
strt = Format(Date, "mm") + 1 & "/1/" & Format(Date, "yyyy") + 1
End Select
End Select
Select Case Format(Date, "mm")
'if month is prior to September then Finish Date defaults to end
of
this
fiscal year
Case 1 To 8
fnsh = "03/31/" & Format(Date, "yyyy") + 1
'if month is September or later then Finish Date defaults to end
of
next
fiscal year
Case 9 To 12
fnsh = "03/31/" & Format(Date, "yyyy") + 2
End Select
' opens text file for output
Open "c:\data\text\WorkCtr.txt" For Output As #2
Print #2, hdr ' prints header information
'generate report
For Each tsk In ActiveProject.Tasks
If tsk.ResourceGroup = "" Or tsk.ResourceNames = "103300" Or
tsk.ResourceNames = "P-103300" Then
Else
Set tsv = tsk.TimeScaleData(strt, fnsh, TimescaleUnit:=pjTimescaleDays)
For hmany = 1 To tsv.Count
badID = tsk.ID
If tsv(hmany).Value = "" Then
Else
Print #2, tsk.Text3 & ";" & tsk.ResourceGroup & ";" & tsk.Text1
& ";" & Format$(tsv(hmany).StartDate, "mm/1/yy") & ";" &
tsv(hmany).Value
/ 60
End If
Next hmany
'StatusBar True, "Outputing Records"
End If
Next tsk
Close #2
'open Excel and create pivot table
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open "C:\Documents and Settings\knewman\Application
Data\Microsoft\Excel\XLStart\PERSONAL.XLS"
XL.Visible = False
XL.Application.Run "PERSONAL.XLS!Project_Data.Work_Center_Load" '
creates table
XL.Application.Run "PERSONAL.XLS!Module15.wchtml" ' creates web page
XL.Application.Quit
Set XL = Nothing
End Sub

**********************************************

I tried replacing my "For Each tsk In ActiveProject.Tasks.....Next tsk"
statement with your code but I got the same result.

In either case the "If tsk.ResourceGroup = "" Or tsk.ResourceNames =
"103300" Or tsk.ResourceNames = "P-103300" Then" statement is where it bombs.

Any help would be appreciated.

Kevin

:

I have a master project that used to consist of subprojects as ile items
within the same file. Hence I could use the following in my VB coding:

"For Each tsk In ActiveProject.Tasks"

Now, in place of these line items, the subprojects are actually inserted
projects that use resources from the same pool and my code bombs.
I
get the
error <Object variable or With block variable not set> when I open
the
macro
in debug mode.

What do I need to do to get it working again?

I need to run a report weekly that shows the resource usage across all
projects within the master project by month

Kevin,
I'm not sure why your code bombs, I would expect it to not give what you
want but otherwise it should run ok. The error message sounds like the
code is trying to refer to an object that isn't defined.

Nonetheless, when working with consolidated projects a different tack is
needed to cycle through all the tasks. Remember, the subtasks of the
inserted projects are NOT part of the master because the subproject are
not part of the master - they are only inserted via a pointer. Here is a
looping structure you can use to look at all tasks in a master. The
first line insures the master is "exploded":

OutlineShowTasks expandinsertedprojects:=True
SelectTaskColumn
Set Area = ActiveSelection.Tasks
For Each t in Area
[your code here]
Next t

Hope this helps.
John
Project MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top