Iterate through Resource Graph view and export to XPS with resources name in VBA Microsoft Project 2010

228 views Asked by At

I am trying to iterate through the Resource Graph view one resource at a time and export to XPS with the appropriate name associated with the file. Here is the code:

Sub ResourcGraph()
' Macro Macro4
' Macro Recorded Tue 6/9/15 by Valencia, Jonathan.


Dim Res As Resource
ViewApply "Resource Graph"

SelectBeginning
For Each Res In ActiveProject.Resources
    If Not Res Is Nothing Then
    DocumentExport FileName:=Res.Name & "Graph", FileType:=pjXPS
    End If
    SelectCellRight
Next Res




End Sub

This code iterates just fine. The problem I am having is getting the name correct.The file is being named by resource but when I click on the file it is the wrong Resource. Is there a way to pull the active resource's information from the Resource Graph view, rather then just going through the resources like I have now?

1

There are 1 answers

1
Rachel Hettinger On BEST ANSWER

This is likely due to the Resource Graph being in a different sort order than the resources in the Resource collection. Instead of trying to sync those up, you can use the Find command to move the graph to the correct resource.

Sub ResourcGraph()

Dim Res As Resource
ViewApply "Resource Graph"

For Each Res In ActiveProject.Resources
    If Not Res Is Nothing Then
        FindEx Field:="Name", Test:="equals", Value:=Res.name, Next:=True
        DocumentExport FileName:=Res.name & "Graph", FileType:=pjXPS
    End If
Next Res

End Sub