Home > database >  Trying to name a resource filter in MS Project
Trying to name a resource filter in MS Project

Time:12-24

Good morning,

I'm trying to set up a VBA automation to cycle through each resource name, and print out a single sheet overview of the entire project that uses that resource (so my guys have a personalized task list of what they need to be doing).

I can pull the value of the various resources assigned to the project, and control the view using:

ResourceName = ActiveProject.Resources(i).Name
ViewApplyEx Name:="&Gantt Chart", ApplyTo:=0

and I can access the filter using:

FilterApply Name:="Using Resource..."

where I get stuck is that I can't seem to actually set the resource value I want. I've tried setting Value1:= "SoAndSo", but that doesn't seem to work (the window popup where I'd set the value doesn't close).

I get a similar problem when I'm trying to print the window. I can get to the print window, but can't get the actual button to register so the printer gets the job.

I'm sure it's a small syntax thing, but I'd appreciate any assistance. Thanks!

CodePudding user response:

This macro loops through the resources, sets the filter and then prints. It's easy to create a new, temporary filter using FilterEdit and then delete it afterwards using OrganizerDeleteItem. Also, the FilePrint method needs at least one parameter otherwise, with no parameters, the dialog box is presented.

Sub PrintTasksForEachResource()

    Dim r As Resource
    For Each r In ActiveProject.Resources
        FilterEdit Name:="tempRes", TaskFilter:=True, Create:=True _
            , OverwriteExisting:=True, FieldName:="Resource Names" _
            , Test:="contains", Value:=r.Name _
            , ShowSummaryTasks:=True
        FilterApply "tempRes"
        FilePrint Color:=True
    Next r

    FilterClear
    OrganizerDeleteItem pjFilters, ActiveProject.Name, "tempres"
    
End Sub

CodePudding user response:

Here's the implementation of my comment about an outer loop (resource) and inner loop (assignments) that effectively creates a resource To Do list. Include whatever Resource/Assignment fields you need. I suggest you pull the timescale data all the way to the right before running the macro so it doesn't appear in the printout. Remove the "preview" option in the print statement when you are ready to print.

Dim r As Resource
Dim a As Assignment
For Each r In ActiveProject.Resources
    r.Flag1 = True
    For Each a In r.Assignments
        a.Flag1 = True
    Next a
    FilterEdit Name:="ResAss", taskfilter:=False, create:=True, overwriteexisting:=True, FieldName:="Flag1", _
        test:="equals", Value:="yes", ShowInMenu:=False, showsummarytasks:=False
    FilterApply Name:="ResAss"
    r.Flag1 = False
    For Each a In r.Assignments
        a.Flag1 = False
    Next a
    FilePrint preview:=True
    FilterClear
Next r
        
End Sub
  • Related