Search code examples
vbams-project

Ms Project VBA Macro Organiser to subproject copy issue


I have a simple line of code that attempts to copy text field via project organiser from a Master project/Global.mpt to subproject within the master project (active project). I have tried multiple ways but i'm failing either with 'Run-time error 1101, the file Schedule 1" was not found Or, "This value is not valid in this situation, check the field to see if it requires a text, date or a number, and that you typed the information correctly". Appreciate your help. Thanks

'OrganizerMoveItem Type:=pjFields, FileName:="MASTER SCHEDULE.mpp", ToFileName:=" Schedule1.mpp", 
Name:="Text27"
'OrganizerMoveItem Type:=pjFields, FileName:="C:\xx\MASTER SCHEDULE.mpp", _
'ToFileName:=ActiveProject, Name:="T27(Text27)"
OrganizerMoveItem Type:=9, FileName:="GLOBAL.MPT", _
ToFileName:=ActiveProject.Subprojects("Schedule1.mpp"), Name:="T27"

Solution

  • The issue is that the subproject file needs to be open in order to use the Organizer to move customizations into it. Viewing the subproject's tasks in the master schedule is not the same as the subproject file being open.

    This code will loop through the subprojects and copy the customized Text27 field to each one by opening it, using the Organizer, then closing and saving it.

    Sub CopyCustomFieldToSubprojects()
    
    Dim master As Project
    Set master = ActiveProject
    
    Dim prj As Subproject
    For Each prj In master.Subprojects
    
        FileOpenEx prj.Path
        Projects(prj.SourceProject.Name).Activate
        
        Application.Alerts False
        OrganizerMoveItem Type:=pjFields, FileName:=master.Name _
            , ToFileName:=ActiveProject.Name, Name:="T27 (Text27)"
        Application.Alerts False
        
        FileCloseEx pjSave
        
    Next prj
    
    End Sub
    

    Note that the OrganizerMoveItem method expects a file name (string) for the FileName and ToFileName parameters rather than a Project object (e.g. Filename:=master.Name).