Error When Changing the Task Publish Field

S

Sam

We have a number of projects that causing the My Tasks error page so I am
attempting to wirte some VBA code that will fix them by changing the Publish
field for each task to "No", publishing the project, then changing it back to
"Yes" and republishing the project. Doing this process manually fixes the My
Tasks error page but I can't seem to get this to work in code.

Here is what I have:

For Each tsk In ActiveProject.Tasks
If Not tsk Is Nothing Then
If Not tsk.Summary Then
tsk.publish = No
End If
End If
Next tsk

This errors with "Object doesn't support this property or method (Error
438)" everytime it hits tsk.publish = No.

Does anyone know what I'm doing wrong?
 
J

Jack Dahlgren

"Sam" - I'd start by using the macro recorder. Turn it on and record that
action. Then stop recording and look at the code. It may give an alternative
way of doing it or some clue as to why your method is not working.
Here is what I get:
SetTaskField Field:="Publish", Value:="No"

The fact that "publish" in your code is not capitalized is a hint that it is
not a real property. As far as I know, the IDE will correctly capitalize
properties and methods so it should correct it to read "tsk.Publish"

I think you need to use the SetField method to set this particular field.

-Jack Dahlgren
 
S

Sam

Thanks for the reply. Your solution works but when you use the
'SetTaskField' it ignores the 'For Each Task' and only works on the selected
task in the project. I've tried to use Get/Set via FieldtoFieldnameConstant
method but i can only get this to work on project fields and not individual
task fields.
 
J

Jack Dahlgren

you need to use that method on the task itself:
Try this line:

Call tsk.SetField(FieldNameToFieldConstant("Publish"), "No")

-Jack Dahlgren
 
J

Jack Dahlgren

You need to identify the task. Try dropping this code into the middle of
your loop:

Call tsk.SetField(FieldNameToFieldConstant("Publish"), "No")

-Jack Dahlgren
 
S

Sam

Thanks Jack! This works perfectly :)

Jack Dahlgren said:
You need to identify the task. Try dropping this code into the middle of
your loop:

Call tsk.SetField(FieldNameToFieldConstant("Publish"), "No")

-Jack Dahlgren
 

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