what's wrong with this code?

K

Kris Rudin

Can't get much simpler:

Sub Macro1()
Dim t As Task

For Each t In Application.ActiveProject.Tasks
t.FixedCost = 0
Next

End Sub

But it throws the wonderful "Object variable or with block not set" error on
the t.fixedCost = 0 line. (It doesn't matter which task property I use, it
throws the same error.)

Intellisense gives me the FixedCost property.

Project Pro 2003.

What basic (no pun intended) thing am I missing here???

Thanks,
Kris Rudin
 
R

Rod Gill

Hi,

If you have a blank task, then that will throw the error. Try:
Sub Macro1()
Dim t As Task

For Each t In Application.ActiveProject.Tasks If NOT (T is nothing) Then
t.FixedCost = 0 End If
Next

End Sub

--
For VBA posts, please use the public.project.developer group.
For any version of Project use public.project
For any version of Project Server use public. project.server

Rod Gill
Project MVP
For Microsoft Project companion projects, best practices and Project VBA
development services
visit www.projectlearning.com/
 
J

JackD

If you have a blank line in your file it will puke on this.

Try:

Sub Macro1()
Dim t As Task
For Each t In ActiveProject.Tasks

if not t is nothing then
t.FixedCost = 0
end if

Next t
End Sub
 
K

Kris Rudin

Ah - light bulb!

Thanks!

Kris

JackD said:
If you have a blank line in your file it will puke on this.

Try:

Sub Macro1()
Dim t As Task
For Each t In ActiveProject.Tasks

if not t is nothing then
t.FixedCost = 0
end if

Next t
End Sub



error
 

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