Project 2010 Macro runs fine on XP but will not work with Windows 7 or remote app Windows Server 2008 R2
-
Tuesday, April 24, 2012 8:11 AM
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- Edited by Steve TRW Tuesday, April 24, 2012 8:14 AM
All Replies
-
Tuesday, April 24, 2012 3:40 PM
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
- Marked As Answer by Steve TRW Monday, April 30, 2012 2:21 PM
-
Tuesday, April 24, 2012 3:50 PMModerator
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 -
Tuesday, April 24, 2012 4:25 PM
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?
- Marked As Answer by Steve TRW Monday, April 30, 2012 2:21 PM
-
Tuesday, April 24, 2012 4:28 PM
John,
Well spotted, i hadent noticed that. Unfortunately the file name is correct, it has a typo on the destination file.
Steve
- Marked As Answer by Steve TRW Monday, April 30, 2012 2:21 PM
-
Tuesday, April 24, 2012 4:57 PM
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
- Marked As Answer by Steve TRW Monday, April 30, 2012 2:21 PM
-
Wednesday, April 25, 2012 12:05 AMModerator
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- Marked As Answer by Steve TRW Monday, April 30, 2012 2:21 PM
-
Wednesday, April 25, 2012 7:07 AM
John,
No it has found the file and opened it then gives the error. Very strange indeed.
Steve
- Marked As Answer by Steve TRW Monday, April 30, 2012 2:21 PM
-
Wednesday, April 25, 2012 7:11 AM
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
- Edited by Steve TRW Wednesday, April 25, 2012 7:24 AM
-
Thursday, April 26, 2012 8:41 PMModerator
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- Marked As Answer by Steve TRW Monday, April 30, 2012 2:21 PM
-
Thursday, April 26, 2012 9:11 PMModerator
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- Marked As Answer by Steve TRW Monday, April 30, 2012 2:21 PM
-
Friday, April 27, 2012 1:18 AMModerator
I clearly have too much time on my hands!!Rod Gill
The one and only Project VBA Book
Rod Gill Project Management
- Marked As Answer by Steve TRW Monday, April 30, 2012 2:21 PM
-
Monday, April 30, 2012 12:35 PM
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
-
Monday, April 30, 2012 2:20 PM
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 -
Monday, April 30, 2012 7:44 PMModerator
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
- Marked As Answer by Steve TRW Monday, August 06, 2012 10:53 AM

