I am one of the authors and current owner of a spreadsheet template which is used by many staff members in my organization. This particular workbook has a great deal going on, but one item in particular plagues me. At one point, someone wrote a macro to import resources and hours from an MS Project file into a worksheet in the tool. From time to time I have tried to resolve the issue with using different versions of MS Project with the tool. I though I had implemented late binding some time ago, but continued to see the problem. Just recently I realized that it was because I neglected to deselect the library in References before publishing the new template. So I gleefully assumed that I had finally resolved the issue, did a little testing, and deployed it.
Wrong! Now, with the MS Project library deselected I get a compile error (variable not defined). The "variable" it complains about is the pjDoNotSave option that's part of the Project file close and exit command.
I can only assume that once again I've missed something. So here's the important part of the code and hopefully someone will spot what I'm doing wrong before I pull out my hair or perhaps suggest a more clever way to close an MS Project file without saving from Excel. Thanks in advance for any help.
____________________________________________
Sub AddResourcesFromProject()
' This Macro adds each resource name and hours for each week from mpp file into the "MPP Estimate" sheet's "Original Estimated Labor" section
' It also set the project's start date in spreadsheet as the project start date in mpp and updates total project weeks . To be able to run this macro, mpp file should be in the same directory as the spreadsheet file.
Const DateColNum = 12
Dim Proj As Object
Dim Res As Object
Dim TSV As Object
Dim TotalWeeks As Object
Dim i As Long
Dim j As Integer
Dim ResColNum As Integer
Dim xlRange As Excel.Range
Dim ProjectName As String
Dim FileToOpen As Boolean
Dim d As Date
Dim projStartDate As Date
Dim k As Integer
Dim importRoles As Integer
Set Proj = CreateObject("MSProject.Application")
ProjectName = InputBox("Enter Project File Name: ")
If Not FileExists(ActiveWorkbook.Path & "\\" & ProjectName) Then
Application.ScreenUpdating = True
MsgBox ("Cannot find file " & ProjectName & " in the folder " & ActiveWorkbook.Path & ". MS Project File must be in the same folder as the Project Workbook.")
Exit Sub
End If
Proj.FileOpen (ActiveWorkbook.Path & "\\" & ProjectName)
...
Proj.FileCloseEx pjDoNotSave
Set Proj = Nothing
AppActivate "Microsoft Excel"
' Turn on all screen updates
Application.ScreenUpdating = True
End Sub
Bookmarks