how to get subprojects' file propertites.

J

Joy

we are using ms project and not Server now

we have our server. if a project is associated with server, it has a project
ID. if it isnot, it has no ID

we may have serveral subprojects linked to a master project.

the following is the code to get each subproject's ID if it has, if not, we
get nothing
Sub Sub_Projects()

Dim subproj As Subproject
Dim myproj As Project
'go through all the subprojects in the file
For Each subproj In ActiveProject.Subprojects
'open them all in turn
FileOpen Name:=subproj.Path
Set myproj = ActiveProject
Dim prop As Object
Dim result As String

' Go thru the custom document properties looking for this specific property
For Each prop In myproj.CustomDocumentProperties
If prop.Name = "ProjectID" Then
Set prop = myproj.CustomDocumentProperties.Item("ProjectID")
result = prop.value

End If
Next prop


Next subproj

End Sub

the problem is here:
For Each prop In myproj.CustomDocumentProperties
If prop.Name = "ProjectID" Then
Set prop = myproj.CustomDocumentProperties.Item("ProjectID")
result = prop.value

End If
Next prop

If I do not check whether a property item named "ProjectID" exists, if a
subproject does not have a project ID, it the VBA will give error msg.

I am wondering how to check if a property item exists?? the code above seems
not worked.
I debugged, I find that prop.name does not show name, but show value. like
prop.name is "$0.00", instead of cost.

I am confused. how to make it right??
 
J

Joy

sorry, later I got it

just add

On Error GoTo PropertyReturn


....
propertyreturn:
' tem not found
 

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