Project 2010 Macro runs fine on XP but will not work with Windows 7 or remote app Windows Server 2008 R2

תשובה Project 2010 Macro runs fine on XP but will not work with Windows 7 or remote app Windows Server 2008 R2

  • 2012年4月24日 8:11
     
     

    Hi,

    I have created this thread as a result of a previous one. http://social.technet.microsoft.com/Forums/en/projectprofessional2010general/thread/61c114e3-ef33-4040-8477-84c542a167eb

    I have tried to create a simple Macro to exchange info from the organizer to other files. The macro below works fine with XP OS but does not work  with Windows 7 OS or our remote app licence running Windows Server 2008 R2. The error is as follows "Run-time error '1101': The file "project1" was not found"

    Does anyone have any ideas regarding this issue? ( FYI  we are using project 2010, we are NOT running project sever, the testing has been carried out locally & on a remote app server running Windows Server 2008 R2 )

    Regards

    Steve

    Sub x()
    Dim strFilename As String
    Dim strPath As String
    Dim P As Project
    Application.ScreenUpdating = False

    strPath = "C:\files to dopy and paste\"

    strFilename = Dir(strPath & "*.mpp")
    Do While Len(strFilename) > 0
    Application.FileOpenEx (strPath & strFilename)
    Set P = Application.ActiveProject

    OrganizerMoveItem Type:=1, FileName:="Global.MPT", ToFileName:=P.Name, Name:="TRW Gantt"                     ******ERROR IS ON THIS LINE********
    OrganizerMoveItem Type:=9, FileName:="Global.MPT", ToFileName:=P.Name, Name:="Project File Owner (Text9)"

    FileClose pjSave
    strFilename = Dir
    Loop
    Application.ScreenUpdating = True
    End Sub


    • 已編輯 Steve TRW 2012年4月24日 8:14
    •  

所有回覆

  • 2012年4月24日 15:40
     
     已答覆

    Steve,

    This might seem pretty dumb but I notice your path is "C:\files to dopy and paste\". Shouldn't that be "C:\files to copy and paste\"?

    John

    • 已標示為解答 Steve TRW 2012年4月30日 14:21
    •  
  • 2012年4月24日 15:50
    版主
     
     

    Well it will run on SOME Win7 machines since I wrote it on my Win7 machine.

    Im on Windows 7 Professional Service Pack 1 X64

    Project Professional 2010 14.0.6112.5000 (32bit)


    Brian Kennemer - Project MVP
    DeltaBahn Senior Architect
    endlessly obsessing about Project Server…so that you don’t have to.
    Blog | Twitter | LinkedIn

  • 2012年4月24日 16:25
     
     已答覆

    Brian,

    You seem to be on an identical setup to me which makes this all the more puzzling, do you think there may be any OS settings that i may have set to cause the issue?

    • 已標示為解答 Steve TRW 2012年4月30日 14:21
    •  
  • 2012年4月24日 16:28
     
     已答覆

    John,

    Well spotted, i hadent noticed that. Unfortunately the file name is correct, it has a typo on the destination file.

    Steve

    • 已標示為解答 Steve TRW 2012年4月30日 14:21
    •  
  • 2012年4月24日 16:57
     
     已答覆

    Steve,

    I wondered if that's why it couldn't find the file. I assume from your response that it still doesn't work even with that correction.

    John

    • 已標示為解答 Steve TRW 2012年4月30日 14:21
    •  
  • 2012年4月25日 0:05
    版主
     
     已答覆

    project1 as a name suggest an unsaved project. Try saving it first then try again. File names need .mpp or .mpt at the end, but this may be the bit that differs between windows versions.

    Just thought: a fileopen may have failed and the macro is trying to copy to the default Proejct1 project created when Project is started.

    Try adding an error test to make sure the project opens correctly before running the OrganizerMoveItem commands.


    Rod Gill

    The one and only Project VBA Book Rod Gill Project Management

    • 已標示為解答 Steve TRW 2012年4月30日 14:21
    •  
  • 2012年4月25日 7:07
     
     已答覆

    John,

    No it has found the file and opened it then gives the error. Very strange indeed.

    Steve

    • 已標示為解答 Steve TRW 2012年4月30日 14:21
    •  
  • 2012年4月25日 7:11
     
     

    Rod,

    Thanks, i had just saved a blank project and used the default naming project1, project2, & project3 etc etc etc. Just for the purpose of testing.

    Thae same files and the same macro ran fine on a colegues pc.

    Steve


    • 已編輯 Steve TRW 2012年4月25日 7:24
    •  
  • 2012年4月26日 20:41
    版主
     
     已答覆 包含代碼

    When doing something like a fileopen you should still have error checking. If the file doesn't open, or opens in read only because someone else has it open, then your code needs to know. Failure to open means your macro is doing actions on the active project, not the intended project: could be awkward!

    Try the following and look in the immediate window for error messages.

    Sub x()
    Dim strFilename As String
    Dim strPath As String
    Dim P As Project
    Application.ScreenUpdating = False
    On Error Resume Next
    strPath = "C:\files to dopy and paste\"
    strFilename = Dir(strPath & "*.mpp")
    Do While Len(strFilename) > 0
        Err.Clear
        Application.FileOpenEx (strPath & strFilename)
        If Err.Number = 0 Then
            Set P = Application.ActiveProject
            
            OrganizerMoveItem Type:=1, FileName:="Global.MPT", ToFileName:=P.Name, Name:="TRW Gantt"
            Debug.Print "OrganizerMoveItem error: " & Err.Description
            OrganizerMoveItem Type:=9, FileName:="Global.MPT", ToFileName:=P.Name, Name:="Project File Owner (Text9)"
        Else
            Debug.Print "Error: " & Err.Description
        End If
        FileClose pjSave
        strFilename = Dir
    Loop
    Application.ScreenUpdating = True
    End Sub


    Rod Gill

    The one and only Project VBA Book Rod Gill Project Management

    • 已標示為解答 Steve TRW 2012年4月30日 14:21
    •  
  • 2012年4月26日 21:11
    版主
     
     已答覆
    Excellent Rod. I had it on my list today to add some Immediate window writing for debugging but had not hit it yet. thanks! :-)

    Brian Kennemer - Project MVP
    DeltaBahn Senior Architect
    endlessly obsessing about Project Server…so that you don’t have to.
    Blog | Twitter | LinkedIn

    • 已標示為解答 Steve TRW 2012年4月30日 14:21
    •  
  • 2012年4月27日 1:18
    版主
     
     已答覆
    I clearly have too much time on my hands!!

    Rod Gill

    The one and only Project VBA Book

    Rod Gill Project Management

    • 已標示為解答 Steve TRW 2012年4月30日 14:21
    •  
  • 2012年4月30日 12:35
     
     

    Rod,

    Thanks so much for your help, i have tried this in addition to renaming the files to something more original. The macro does run with no errors but unfortunately does not make any chages. Should i see an error if the files are not able to open for some reason?

    I will keep trying

    Regards

    Steve

  • 2012年4月30日 14:20
     
     已答覆

    Rod / Brian,

    Thank-you both for your assistance. I have now (with the assistance of a helpful friend at work & you guys) managed to get a macro that works for me.

    Steve

    Sub steve_test()
    Dim strFilename As String
    Dim strPath As String
    Dim P As Project
    Dim strFileLoc
    Application.ScreenUpdating = False
    On Error Resume Next
    strPath = "D:\SharedProjects\Test Area All Users\stevemacrotest\"
    strFilename = Dir(strPath & "*.mpp")
    Do While Len(strFilename) > 0
        Err.Clear
        strFileLoc = strPath & strFilename
        Application.FileOpenEx (strFileLoc)
        If Err.Number = 0 Then
            Set P = Application.ActiveProject
            OrganizerMoveItem Type:=1, FileName:="Global.MPT", ToFileName:=strFileLoc, Name:="TRW Gantt"
            'OrganizerMoveItem Type:=1, FileName:="Global.MPT", ToFileName:=P.Name, Name:="TRW Gantt"
            Debug.Print "OrganizerMoveItem error: " & Err.Description
            OrganizerMoveItem Type:=9, FileName:="Global.MPT", ToFileName:=strFileLoc, Name:="Project File Owner (Text9)"
            'OrganizerMoveItem Type:=9, FileName:="Global.MPT", ToFileName:=P.Name, Name:="Project File Owner (Text9)"
        Else
            Debug.Print "Error: " & Err.Description
        End If
        FileClose pjSave
        strFilename = Dir
    Loop
    Application.ScreenUpdating = True
    End Sub


    • 已標示為解答 Steve TRW 2012年4月30日 14:21
    • 已編輯 Steve TRW 2012年4月30日 14:22
    •  
  • 2012年4月30日 19:44
    版主
     
     已答覆
    The error messages will pile up in the immediate window of the VBE. You can change the debug.print command to a msgbox, but that stops progress until you click OK each time.

    Rod Gill

    The one and only Project VBA Book

    Rod Gill Project Management

    • 已標示為解答 Steve TRW 2012年8月6日 10:53
    •