Integrations with MS Project Resources

Eurekaonide

Active Member
Joined
Feb 1, 2010
Messages
422
Hi
I don't know if this is possible, however I have to open up multiple MS Project plans go to a specific custom view on the resource tab and copy out the resource data and timeline data on the right (allocations) paste both into Excel (this has to be done in a 2 step, names then the allocations) - is it possible to automate this?
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
There may be a way to do this. I've done a lot of code to access Project data from Excel. However, I need a LOT more detail about what you need to do.

The Resource tab does not have views; the views are on the View tab.

The Project object model is not really focused on views, it's focused on the underlying data. I'm not sure if you can access views through VBA. However, it's hard for me know what data you want if I can't see the view you're talking about, since it's a custom view. Can you post a screen shot?
 
Upvote 0
Hi Thank you for replying,
The custom view is not all that custom really it was just a way of me getting the columns I needed quickly.

It basically has
Enterprise Unique ID
Resource Name
Work

All within the resources section

I set it to days as a schedule in the options under file.

I then just select the date range I'm after but I could be flexible with this as long as it reached end of 2021

I just then paste these into an excel worksheet, Ive pretty much sorted the vba code to format it after I have downloaded it.

Any help would be appreciated, we have PWA but we are not allowed access to the back end data and its not set up correctly with access and permissions its very tiresome!
 
Upvote 0
Is this Microsoft Project desktop software, or Microsoft Project Server?
 
Upvote 0
They are stored on ProjectServer but I take a copy down to MS Project desktop software and that's where I will run it from.
 
Upvote 0
The code below will do it. The code is intended to run in a standard module. The code assumes there is a worksheet with a codename of Resources. It blanks out any existing data (leaves formatting) and writes headers for the three columns.

It prompts the user to locate the Project file to use. It has to open the file to do the work, then it closes it.

It retrieves the total work for all resources, using the three columns you listed above. I didn't understand what you meant by the following, because it didn't seem to sync with the other part of your description and I don't know what screen you are looking at when you do this:
I set it to days as a schedule in the options under file.

I then just select the date range I'm after but I could be flexible with this as long as it reached end of 2021
If what I have provided is not what you're looking for then you will need to provide a lot more detail, including screen shots of what your description refers to, as I suggested in post #2. Include the sample data from your project file, and an image of what you want the result to look like in your Excel file.

Modify to suit.
VBA Code:
Option Explicit

Dim MSP As Object  ' Project application


Private Sub ExtractResources()
   
   Dim SourceProject As Object
   Dim i As Long
   
   
   
   Set MSP = CreateObject("MSProject.Application")
   Set SourceProject = OpenProject()
   
   
   With Resources
   
      .Activate
      .Cells.ClearContents
      
      .Cells(1, "A") = "Enterprise Unique ID"
      .Cells(1, "B") = "Name"
      .Cells(1, "C") = "Work (Hours)"
      
      For i = 1 To SourceProject.Resources.Count
         .Cells(i + 1, "A") = SourceProject.Resources(i).EnterpriseUniqueID
         .Cells(i + 1, "B") = SourceProject.Resources(i).Name
         .Cells(i + 1, "C") = SourceProject.Resources(i).Work / 60 ' work is in units of minutes, convert to hours
      Next i
   
   End With
   
   MSP.FileExit ProjectConstants.pjDoNotSave

End Sub



' Open Project and prompt the user for a Project file to open
' Return value is the Project object
' Project is left open, minimized
'Public Function openProject(prompt As String) As Project
Public Function OpenProject() As Object ' Project

   ' Create the Project application object.  This prevents errors if
   ' executing this code again in the same run of Excel as opposed to
   ' simply using ExcelExport_Apps.MSProject
   ' Set ExcelExport_Apps.MSP = CreateObject("ExcelExport_Apps.MSProject.Application")
   
   'MsgBox prompt:=prompt, Title:="Open MS Project File"
   
   MSP.FileOpen
   
   On Error GoTo NoProject
   Set OpenProject = MSP.activeproject
   On Error GoTo 0
   
   MSP.AppMinimize
   
   Exit Function
   
NoProject:
   
   MSP.FileExit
   Set OpenProject = Nothing
   
   If Err.Number = 424 Then
      ' File not found
      MsgBox "No Project selected, exiting."
   Else
      MsgBox "Unexpected error attempting to open Project file" & vbCrLf & _
             "Exiting." & vbCrLf & _
             Err.Number & " " & Err.Description
   End If
   
   Exit Function

End Function
There is another module called ProjectConstants with this code:
VBA Code:
Option Explicit

Public Const pjDoNotSave = 0
 
Upvote 0
Solution
The code below will do it. The code is intended to run in a standard module. The code assumes there is a worksheet with a codename of Resources. It blanks out any existing data (leaves formatting) and writes headers for the three columns.

It prompts the user to locate the Project file to use. It has to open the file to do the work, then it closes it.

It retrieves the total work for all resources, using the three columns you listed above. I didn't understand what you meant by the following, because it didn't seem to sync with the other part of your description and I don't know what screen you are looking at when you do this:

If what I have provided is not what you're looking for then you will need to provide a lot more detail, including screen shots of what your description refers to, as I suggested in post #2. Include the sample data from your project file, and an image of what you want the result to look like in your Excel file.

Modify to suit.
VBA Code:
Option Explicit

Dim MSP As Object  ' Project application


Private Sub ExtractResources()
  
   Dim SourceProject As Object
   Dim i As Long
  
  
  
   Set MSP = CreateObject("MSProject.Application")
   Set SourceProject = OpenProject()
  
  
   With Resources
  
      .Activate
      .Cells.ClearContents
     
      .Cells(1, "A") = "Enterprise Unique ID"
      .Cells(1, "B") = "Name"
      .Cells(1, "C") = "Work (Hours)"
     
      For i = 1 To SourceProject.Resources.Count
         .Cells(i + 1, "A") = SourceProject.Resources(i).EnterpriseUniqueID
         .Cells(i + 1, "B") = SourceProject.Resources(i).Name
         .Cells(i + 1, "C") = SourceProject.Resources(i).Work / 60 ' work is in units of minutes, convert to hours
      Next i
  
   End With
  
   MSP.FileExit ProjectConstants.pjDoNotSave

End Sub



' Open Project and prompt the user for a Project file to open
' Return value is the Project object
' Project is left open, minimized
'Public Function openProject(prompt As String) As Project
Public Function OpenProject() As Object ' Project

   ' Create the Project application object.  This prevents errors if
   ' executing this code again in the same run of Excel as opposed to
   ' simply using ExcelExport_Apps.MSProject
   ' Set ExcelExport_Apps.MSP = CreateObject("ExcelExport_Apps.MSProject.Application")
  
   'MsgBox prompt:=prompt, Title:="Open MS Project File"
  
   MSP.FileOpen
  
   On Error GoTo NoProject
   Set OpenProject = MSP.activeproject
   On Error GoTo 0
  
   MSP.AppMinimize
  
   Exit Function
  
NoProject:
  
   MSP.FileExit
   Set OpenProject = Nothing
  
   If Err.Number = 424 Then
      ' File not found
      MsgBox "No Project selected, exiting."
   Else
      MsgBox "Unexpected error attempting to open Project file" & vbCrLf & _
             "Exiting." & vbCrLf & _
             Err.Number & " " & Err.Description
   End If
  
   Exit Function

End Function
There is another module called ProjectConstants with this code:
VBA Code:
Option Explicit

Public Const pjDoNotSave = 0
I cannot THANK YOU Enough! You are truly amazing Thank you and Happy New Year :)
 
Upvote 0
You are very welcome! I am relieved that it worked for you. Sometimes these things bounce back and bite me. ?

Happy new year!
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top