none
[ver2007] link/unlink projects to a pool via macro: save or not save? This is the question! RRS feed

  • Question

  • Hi to all

    Is necessary to save project linked when un-link it from the pool? And when link it?

    Which is the correct steps to avoid error?

    The question came from this case:

    I'm try to automate link/unlink a set of project files to a file pool, using macro written inside the pool file.

    I'm going in trouble with some error. I token usefull suggestion on this forum but... I notice a think.

    The macros seems to work but...

    A) when I link the set of pool I call this method..

    Sub agganciaProgetti_BL(fileProjectsToLink As String)
        
        Dim lineFileProject As String
        Dim filePool As String
        
        filePool = Application.ActiveProject.FullName
        
        Dim bCalcMode As Boolean
        bCalcMode = Application.Calculation
        Application.Calculation = pjManual
        
        Open fileProjectsToLink For Input As #1
        
        Dim pj As MSProject.Project
        Dim pjPool As MSProject.Project
        Set pjPool = Application.ActiveProject
        
        While Not EOF(1)
        
            Line Input #1, lineFileProject
            
            If esisteFile(lineFileProject) Then
            
               Application.FileOpenEx lineFileProject, openPool:=pjPoolReadWrite
               Set pj = Application.ActiveProject
               
               On Error GoTo 0
               On Error GoTo InsertProjectNotOpen
               Projects("" & pj & "").Activate
               
               On Error GoTo 0
               pj.Application.ResourceSharing share:=True, Name:=filePool, Pool:=True
                          
               FileClose pjSave, False
               Set pj = Nothing
                
            Else
                MsgBox "ATTENZIONE <" & lineFileProject & "> NON ESISTE"
            End If
            
            
        Wend
        Close #1
        
        Application.Calculation = bCalcMode
        FileClose pjSave, False
        
        Exit Sub
        
    InsertProjectNotOpen:
       WindowNewWindow "" & pj & ""
       Resume
       
    SetPoolForConsolProjs:
       Application.Calculation = bCalcMode
       Resume
       
    End Sub


    When I UNLINK. ... I run this:

    Sub UnlinkSharerFil()
        Dim Shar() As String, s As String
        Dim sp As Subproject
        Dim NumShar As Integer, i As Integer
        'open all sharer files into temporary master, count them and
        ' set up array to hold sharer file path names
        
        On Error GoTo PoolVuoto
        ResourceSharingPoolAction Action:=pjOpenAllSharers
        On Error GoTo 0
        
        NumShar = ActiveProject.Subprojects.Count
        ReDim Shar(NumShar)
        i = 0
        'fill array with sharer file path names
        For Each sp In ActiveProject.Subprojects
            Shar(i) = sp.SourceProject.FullName
            i = i + 1
        Next sp
        'close temporary master
        FileCloseEx Save:=pjDoNotSave
        'unlink all sharer files
        For i = 0 To NumShar - 1
            ResourceSharingPoolAction Action:=pjUnlinkSharer, FileName:=Shar(i)
            s = s & vbCrLf & Shar(i)
            
        Next i
    
        'MsgBox s
        Exit Sub
        
    PoolVuoto:
        MsgBox "Pool senza progetti collegati"
        Exit Sub
        
        
    End Sub

    The question is... why is not necessary to save the file when unlink?

    Tuesday, March 12, 2013 10:21 AM

Answers

  • Danieleb75,

    It IS necessary to save the pool file and each sharer file after unlinking. That is the only way the link structure will be properly broken. In the macro I provided for you the pjDoNotSave applies only to the temporary master. The temporary master is only created to provide a convenient way to gather the sharer file names into an array.

    John

    • Marked as answer by danieleb75 Wednesday, March 13, 2013 4:12 PM
    Tuesday, March 12, 2013 4:16 PM

All replies

  • Danieleb75,

    It IS necessary to save the pool file and each sharer file after unlinking. That is the only way the link structure will be properly broken. In the macro I provided for you the pjDoNotSave applies only to the temporary master. The temporary master is only created to provide a convenient way to gather the sharer file names into an array.

    John

    • Marked as answer by danieleb75 Wednesday, March 13, 2013 4:12 PM
    Tuesday, March 12, 2013 4:16 PM
  • Thank John...

    did you mean "That is the only way the link structure will NOT be properly broken" ?

    so how do you suggest to modify my code?

    When I unlink I have to open the project sharer ... launch

    ResourceSharingPoolAction Action:=pjUnlinkSharer, FileName:=Shar(i)

    and then close with save?

    Why now my code works? After my macro I find my project sharer correctly unlinked.

    Thank you a lot.


    Wednesday, March 13, 2013 10:23 AM
  • danieleb75,

    No, I meant exactly what I said. Linked structures in Project have two parts to each link - the source "tag" and the destination "tag" (there may be a more formal term for it but I'm using "tag" simply for convenience). In order to properly break both parts of the link, both the source file and the destination file must be saved. If not, a link fragment can remain in the file that was not saved and this can lead to file corruption. Therefore I always advocate saving both files whenever cross-projects are broken, whether it's files with cross-project links (i.e. external predecessors/successors), master/subproject files, or resource pool/sharer files.

    The intent of my original macro was to show how to get the sharer file names. I did not concern myself about the saving aspect. That was probably bad practice on my part. I've re-written the macro to unlink the pool and all sharer files and save everything when done. There may be more efficient ways to do this but at least this code should work.

    Sub UnlinkSharerFil()
    Dim Shar() As String
    Dim sp As Subproject
    Dim NumShar As Integer, i As Integer
    Dim PoolNam As String
    'open all sharer files into temporary master, count them and
    ' set up array to hold sharer file path names
    ResourceSharingPoolAction Action:=pjOpenAllSharers
    NumShar = ActiveProject.Subprojects.Count
    ReDim Shar(NumShar)
    i = 0
    'fill array with sharer file path names
    For Each sp In ActiveProject.Subprojects
        Shar(i) = sp.SourceProject.FullName
        i = i + 1
    Next sp
    'close temporary master and get name of pool file
    FileCloseEx Save:=pjDoNotSave
    PoolNam = ActiveProject.Name

    'open sharer files
    For i = 0 To NumShar - 1
        FileOpen Name:=Shar(i)
    Next i
    'activate pool file and unlink all sharer files
    Projects(PoolNam).Activate
    For i = 0 To NumShar - 1
        ResourceSharingPoolAction Action:=pjUnlinkSharer, FileName:=Shar(i)
    Next i
    'save changes
    FileCloseAllEx Save:=pjSave
    End Sub

    John

    Thursday, March 14, 2013 2:41 AM