We run a lot of project files and want to update / replace existing custom fields with new lookups and formulas that are stored in our global file when I open the file.
I've come up with the following code but the problem is that it doesn't append the ".mpp" file type if the file has been saved. I've also tried "ActiveProject.FullName", however this returns runtime 1101 error.
I don't want to hardcode the filename as this would by a nightmare to manage.
Any ideas on how to resolve this?
thanks in advance
Sub DeleteUpdateFields()
OrganizerDeleteItem pjFields, FileName:=ActiveProject.Name, Name:="Test (Text19)"
OrganizerMoveItem pjFields, FileName:="Global.MPT", ToFileName:=ActiveProject.Name, Name:="Test (Text19)"
End sub
CodePudding user response:
Joe, You don't specify if the extension (.mpp) is always missing or just for some files but here's a bit of code that will first test for the extension and then add it if it's missing.
The reason you got the runtime error is because ActiveProject.FullName includes the path which is not a valid argument in this instance.
I assume your code runs as an Open Event in each file rather then you having to initiate the macro for each file. If not, let us know.
Option Compare Text
Sub DeleteUpdateFields()
Dim FNam As String
FNam = ActiveProject.Name
If InStr(1, ActiveProject.Name, ".mpp") = 0 Then
FNam = ActiveProject.Name & ".mpp"
End If
OrganizerDeleteItem pjFields, FileName:=FNam, Name:="Test (Text19)"
OrganizerMoveItem pjFields, FileName:="Global.MPT", ToFileName:=FNam, Name:="Test (Text19)"
End Sub
Hope this helps. John