Project 2010 Macro runs fine on XP but will not work with Windows 7 or remote app Windows Server 2008 R2
-
יום שלישי 24 אפריל 2012 08: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 יום שלישי 24 אפריל 2012 08:14
כל התגובות
-
יום שלישי 24 אפריל 2012 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 יום שני 30 אפריל 2012 14:21
-
יום שלישי 24 אפריל 2012 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 -
יום שלישי 24 אפריל 2012 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 יום שני 30 אפריל 2012 14:21
-
יום שלישי 24 אפריל 2012 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 יום שני 30 אפריל 2012 14:21
-
יום שלישי 24 אפריל 2012 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 יום שני 30 אפריל 2012 14:21
-
יום רביעי 25 אפריל 2012 00: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 יום שני 30 אפריל 2012 14:21
-
יום רביעי 25 אפריל 2012 07:07
John,
No it has found the file and opened it then gives the error. Very strange indeed.
Steve
- סומן כתשובה על-ידי Steve TRW יום שני 30 אפריל 2012 14:21
-
יום רביעי 25 אפריל 2012 07: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 יום רביעי 25 אפריל 2012 07:24
-
יום חמישי 26 אפריל 2012 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 יום שני 30 אפריל 2012 14:21
-
יום חמישי 26 אפריל 2012 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 יום שני 30 אפריל 2012 14:21
-
יום שישי 27 אפריל 2012 01: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 יום שני 30 אפריל 2012 14:21
-
יום שני 30 אפריל 2012 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
-
יום שני 30 אפריל 2012 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 -
יום שני 30 אפריל 2012 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 יום שני 06 אוגוסט 2012 10:53