Open Microsoft Project File

Recently I’ve been playing around on how to open a Microsoft Project file using Excel with VBA. This script should work at minimum for current versions of Microsoft Project. If you need it for an earlier version, it should be similar, so play around with the code.

Click on ToolsReferencesMicrosoft Project xx.x Object Library. Then click okay. Ready to Access Microsoft Project from Excel. Now you are ready to start coding in Excel to access information from Microsoft Project. Let’s start by opening a Microsoft Project file from Excel. Make sure to first set up your variables, which in this script you. How to connect to Project Online. You can do the following to connect to your Project Online site in your Office 365 environment: After opening the Project Online Desktop Client, at the login screen, for Profile select Computer, and then select OK. On the next screen, select Blank project. On the new project page, select the File menu.

Start in Excel with VBA

You can build a procedure Sub in your VBA Editor after you add a new Module to your current workbook.

Before starting to write your code, make sure you have the right references to access Microsoft Project! Click on Tools>References>Microsoft Project xx.x Object Library. Then click okay.

Ready to Access Microsoft Project from Excel

Now you are ready to start coding in Excel to access information from Microsoft Project. Let’s start by opening a Microsoft Project file from Excel.

Make sure to first set up your variables, which in this script you only need one. You will need one variable for your MS Project application, which I called projApp.

Using Error Handling

I use the On Error Resume next in case MS Project is not installed and an error occurs. This way the code stops running and you don’t get an error. We set projApp to be a new instance of the object type. This means we can now access everything we need in MS Project.

NOTE: Every time you run a new Macro / VBA script you run a risk of losing all your work. When trying out new code I recommend you use it on copies of your projects and not on active projects. This way if your VBA doesn’t run correctly, you won’t lose valuable information. Run it at your own risk!

Where you see “C:<>My Example Project.mpp”, this is where you put the information on where YOUR file is located. I took out most of my file path to not make it confusing

Of course, this is just the staring code where it just opens the Microsoft Project, you will need to write more code to do what you want it to do.

The last comment I want to make is that about the project file you might be trying to open. I have found that if your project file has macros, then you might have trouble using this macro because of Microsoft built in security. You might have to change the security settings so that your macro can work.

Open Microsoft Project File

Open Microsoft Project File

Otherwise, it works like a charm!

Online

If you want to learn how to start with VBA, check out one of my posts on looping through tasks using the For Each…Next loop.

Learn Microsoft Project VBA

VBA editor using the View tab or the Developer tab

Navigate the VBA Editor

  • Object Browser window
  • Project Explorer window
  • Toolbars
    • Standard toolbar
    • Edit toolbar
    • Debug toolbar
    • UserForm toolbar
    • Custom toolbar

Use Option Explicit

Use the message box (MsgBox) function

Change the text of all tasks to all lowercase or all uppercase

Loop through tasks and resources using for each....next loops

Open Microsoft Project File Online

Manually export VBA modules

Open Microsoft Project File Without Project

Method 1 - Because of the way Project stores files, file fragmentation may be the basic cause. To make sure this isn’t the problem: open your .mpp file then select File/Save immediately before doing any other action. Only if you save immediately after opening does Project defragment its .mpp file. If you do not have external links in your file, (i.e. resource pool, master with subprojects, etc.), then a good practice is to always use Save As instead of a straight Save with your file after editing. This helps keep editing clutter from being appended to the file. However, be advised that using Save As with linked files can actually create corruption/bloat due to multiple link paths being created IF the file is not saved back to its original name and path.
Method 3 - Repeat the above steps except for step 3, Save As to .xml.
Method 4 - (Be advised that this will eliminate all custom formatting and that the new blank file created in step 1 should be pre-formatted with custom views, fields, calendars, etc.
(Try using the organizer to import such from the Global .mpt))
Article: http://www.filerepairforum.com/forum/microsoft/microsoft-aa/project/105-%E2%80%8Bms-project-cannot-save-file-cannot-be-opened
If none of the above is effective, a more advanced approach is to re-create the file from Project's underlying database using VBA. Since the details of this method depend on the structural complexity of the file (e.g. multiple calendars, progress of tasks, levelling applied, etc.) this method should only be attempted by those with extensive Project Repair Kit
Demo version:- http://www.project.repair/
Any help will be appriciated.
Thanks,