Open an mpp file using vba

Solved
blalaa Posted messages 171 Status Member -  
blalaa Posted messages 171 Status Member -
Hello

I would like to open a file of type "Microsoft Office Project Document (.mpp)" (from an Excel workbook) so that I can retrieve data, but I'm having trouble.
I tried using this code, but the format is not suitable.

Sub ChoixFichier()

Dim Fichier As Variant
Fichier = Application.GetOpenFilename("All files (*.*),*.*")

If Fichier = False Then Exit Sub

Workbooks.Open Filename:=Fichier
End Sub


Another question

Once I open the file, can I retrieve data like in Excel or not?

Thank you in advance for your responses.

1 answer

  1. jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830
     
    Hello,

    A simple internet search:
     '~~> Code to open MPP file in Excel Sub Sample() Dim appProj As MSProject.Application Dim aProg As MSProject.Project Dim wb As Workbook Dim ws As Worksheet Set wb = ActiveWorkbook '~~> This is the Sheet Where you want the data to be copied Set ws = wb.Sheets("Sheet1") Set appProj = CreateObject("Msproject.Application") '~~> This is a MS Project File. Change path as applicable. appProj.FileOpen "C:\MS Project.mpp" Set aProg = appProj.ActiveProject appProj.Visible = True '~~> Now you have the MPP file opened, rest of the code goes here End Sub 


    --
    Best regards,
    Jordane
    1
    1. blalaa Posted messages 171 Status Member
       
      Thank you very much
      I will test it

      For my second question: when I open the file, can I retrieve data like Excel or not?

      Thank you again
      0
      1. jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830 > blalaa Posted messages 171 Status Member
         
        Not "like" Excel... but yes, it's possible to retrieve information...
        for example, looping through the different tasks... something like
         For Each Tsk In aProg.Tasks MsgBox Tsk.Name Next 


        Anyway... you have to search...
        The information I'm giving you... I can find it in just a few seconds on forums...
        I don’t have MsProject on hand to test them.
        0
    2. blalaa Posted messages 171 Status Member
       
      Re
      I tried, but there is a compilation error: user-defined type not defined

      Dim appProj As MSProject.Application


      I don’t know where the problem is

      Thanks again
      0
    3. blalaa Posted messages 171 Status Member
       
      I needed to add the Microsoft Project 12.0 Object Library in the VBA references
      it's good it works very well

      thank you very much

      have a good evening
      0