none
Need to read MS Project subproject tasks without re-opening each subproject file RRS feed

  • Question

  • My COM Add-In application reads information from MS Project tasks via COM interop using Microsoft.Office.Interop.MSProject. When the Project object (theProject) contains inserted subprojects, my app reads the tasks like this:

    For Each subProj As Subproject In theProject.Subprojects

       For Each tsk as Task in subProj.SourceProject.Tasks

             Dim id as Integer = tsk.ID

             ...

       Next

    Next

    Even though the user has opened the master project in MS Project and can see all subproject tasks on his screen,  my code causes MS Project to RE-OPEN each subproject file!  I know this because sometimes the subproject files are marked as read-only.   In this case my code forces the user to respond to a user prompt as the code iterates through each subproject.  This is very slow and is a very bad user experience.   Is there some way to iterate through the subproject tasks without having MS Project re-open each subproject file?


    ...Jim Black

    Monday, June 30, 2014 2:55 PM

Answers

  • Hi,

    I think the master file holds a snapshot of data for a subproject when last opened or expanded in the master. When reading tasks, project assumes you want the latest data, so has to open the sub-project. the DisplayAlerts=false should help. If not then you need a better way of having master files than linked ones. Either create unlinked master files for reporting purposes (a macro is an easy way to automate creating them) or maybe have an add-in or macro to copy data to SQL Server for reporting purposes.


    Rod Gill
    Author of the one and only Project VBA Book
    www.project-systems.co.nz

    • Marked as answer by Jim Black CG Tuesday, July 1, 2014 3:24 PM
    Tuesday, July 1, 2014 9:58 AM
    Moderator
  • Jim,

    While Rod is counting sheep I'll field your question. Yes, your understanding is correct. The default setting for inserting subprojects into a master will create a dynamic master meaning that a pointer to each subproject is inserted into the master, (the subprojects do not actually reside in the master), creating a linked structure. Edits to subproject data made at master level will be dynamically linked to the subprojects and vice versa. Although a dynamic master has the benefits of a linked structure it is also unfortunately subject to file corruption. The files in a linked structure must never be moved, renamed, overwritten, or saved off. It is also best if all files reside in the same folder on a local drive. And with the number of files you have in your linked structure, I'd be surprised if you do not see some file corruption at some point.

    In order to avoid the possibility of file corruption, we recommend creating a static master by turning off the "link to project" option in the lower right corner of the Insert Project window. To create a static master Project literally copies the data from each subproject into the master without creating a link. The master is then a snapshot in time of each subproject. Each reporting period a new static master is created and this can be automated with a macro if there are many files, as in your case, or frequent reporting periods.

    Hope this helps.

    John

    • Marked as answer by Jim Black CG Tuesday, July 1, 2014 8:17 PM
    Tuesday, July 1, 2014 5:23 PM
  • Jim,

    Better man huh, well, I don't know about that. Let's just say I'm a good egg who's hoping he won't crack, it would just be too messy.

    You're right in that the display alerts only applies to alerts generated by Project. And yes, if the file is opened read only, then there will be no conflict in the event two users attempt to edit and save the same file at the same time.

    John

    • Marked as answer by Jim Black CG Tuesday, July 1, 2014 11:03 PM
    Tuesday, July 1, 2014 10:58 PM

All replies

  • Jim,

    I just tried a little test in VBA. Indeed querying data from a subproject does open that suproject in the background.

    My first thought about your issue is to question the need for the user prompt. Do you really need it? Assuming it is important to whatever you are doing, you might try this workaround trick. The subproject is opened in the background as soon as the inner loop starts to execute. At that point, open the supbroject in a new window and then immediately close it without saving. Now continue iterating through the tasks of that subproject.

    A bit klugy but it just might work.

    John

    Monday, June 30, 2014 3:42 PM
  • Hi John,

    Thanks for the quick response, the validation test, and the suggestion.   

    Some background: my app is a Windows Form app that connects to MS Project as a COM Add-In.   At the time of the inner loop, my app has no form on the screen.   Rather it is reading MS Project tasks into memory using the MS Project Application object, which gives a reference to the Project object (theProject in my example code).

    Some clarification:  My app is not displaying the user prompt.  MS Project is displaying the prompt.  My goal is to suppress this prompt and all other manifestations of MS Project re-opening files that it has already opened.  The prompt is a consequence of MS Project actions that appear to be beyond my app's control.    There are also annoying tooltips that appear in the lower-left corner of the MS Project window as each subproject file gets opened, but these are not as bad for the end user as dialog boxes that must be dismissed.   Some of my end users have MS Project master files that reference 200 subprojects, so you can imagine their issue with the current behavior.

    I don't fully understand your suggestion, since I never open the subprojects in a Window.  However, I think that having 200 windows opening and quickly closing as MS project goes through 200 subproject files would also be deemed unacceptable "flashing screen behavior" by my end users.  

    I either need to prevent MS Project from re-opening files that the MS Project Application object is already displaying in full detail on the screen, or I need to prevent MS Project from displaying dialogs and tooltips as it iterates through all the files.

    Thanks again for you ideas!


    ...Jim Black



    • Edited by Jim Black CG Monday, June 30, 2014 4:25 PM more typos
    Monday, June 30, 2014 4:19 PM
  • Jim,

    Just for reference I've never worked with COM add-ins so my reference is limited to VBA. If the main issue is the alerts from the Project application, you should be able to suppress them by setting the DisplayAlerts property to false. I do that in virtually all of my macros.

    Yes I agree that my workaround is not ideal and would amount to aggravating screen flashing if there are a quantity of subprojects in the master.

    Perhaps Rod Gill will check into this thread later today when the sun comes around his part of the globe. He might have better ideas.

    John

    Monday, June 30, 2014 5:55 PM
  • Hi John,

    I'll see if I can turn off DisplayAlerts from within a COM Addin.  That sounds like it could be what I'm looking for.   It would be good if Rod could weigh in on this one, too.  I have his book on MS Project 2010 and like it.

    Jim


    ...Jim Black

    Monday, June 30, 2014 6:58 PM
  • Hi,

    I think the master file holds a snapshot of data for a subproject when last opened or expanded in the master. When reading tasks, project assumes you want the latest data, so has to open the sub-project. the DisplayAlerts=false should help. If not then you need a better way of having master files than linked ones. Either create unlinked master files for reporting purposes (a macro is an easy way to automate creating them) or maybe have an add-in or macro to copy data to SQL Server for reporting purposes.


    Rod Gill
    Author of the one and only Project VBA Book
    www.project-systems.co.nz

    • Marked as answer by Jim Black CG Tuesday, July 1, 2014 3:24 PM
    Tuesday, July 1, 2014 9:58 AM
    Moderator
  • Hi Rod,

    Thanks for the definitive answer to my question.   It make sense, though I wish MS Project would let me control the behavior.  We are testing DisplayAlerts=False (thanks to you and John for that!) and will soon know what will happen when the subproject files are read-only.  Hopefully it will just open them in read-only mode without annoying the end user with 200 dialog boxes!   As for your suggestion to unlink the files, I believe that this decouples the master from any future edits made to the subproject files because it copies the contents of the subproject into the master.   Am I correct?

    Thanks again for your help on this.


    ...Jim Black

    Tuesday, July 1, 2014 3:32 PM
  • Jim,

    While Rod is counting sheep I'll field your question. Yes, your understanding is correct. The default setting for inserting subprojects into a master will create a dynamic master meaning that a pointer to each subproject is inserted into the master, (the subprojects do not actually reside in the master), creating a linked structure. Edits to subproject data made at master level will be dynamically linked to the subprojects and vice versa. Although a dynamic master has the benefits of a linked structure it is also unfortunately subject to file corruption. The files in a linked structure must never be moved, renamed, overwritten, or saved off. It is also best if all files reside in the same folder on a local drive. And with the number of files you have in your linked structure, I'd be surprised if you do not see some file corruption at some point.

    In order to avoid the possibility of file corruption, we recommend creating a static master by turning off the "link to project" option in the lower right corner of the Insert Project window. To create a static master Project literally copies the data from each subproject into the master without creating a link. The master is then a snapshot in time of each subproject. Each reporting period a new static master is created and this can be automated with a macro if there are many files, as in your case, or frequent reporting periods.

    Hope this helps.

    John

    • Marked as answer by Jim Black CG Tuesday, July 1, 2014 8:17 PM
    Tuesday, July 1, 2014 5:23 PM
  • John,

    Thank you, sir!   That makes a lot of sense. These are my customers' files, and I am not at all in control of how they configure MS Project at their company. This customer is using my company's COM Add-In software to generate visual reports, and I am trying to make their lives less frustrating when they run our tool on a master that references 200 subprojects.   I will pass along your advice on doing un-linked master files.   I'll be happy to pass along any contact information you want to provide because I suspect this customer might benefit from your advice directly.   Shoot me an email at jblack@chroniclegraphics.com with your contact information if that is something you'd be willing to do.


    ...Jim Black

    Tuesday, July 1, 2014 5:48 PM
  • Jim,

    You're welcome and thanks for the feedback. For your reference I do not have a consulting business like most of my fellow responders on these forums so I do not "hire out", although I do from time to time work directly with some users who post on the forum to help work an issue that cannot be readily resolved through forum postings. I'm simply a guy who has a fair amount of experience with Project (many years) and I like to help/share my experience with other Project users. If your customer has specific issues with Project, they are more than welcome to post to the forum

    If you find my help useful, I appreciate a vote or mark as answer. That's how we get "paid" for our participation in the Project forums.

    John

    Tuesday, July 1, 2014 6:55 PM
  • John,

    You're a better man than I!   Thanks for the help.   I'm happy to vote and mark as answer for both you and Rod.

    By the way, I stumbled upon an interesting twist that may explain what is really happening to my customer.  I wanted to test your DisplayAlerts=False idea, so  I tried like crazy to reproduce the appearance of a bunch of "Read-Only" dialog boxes during my product's reading of the subproject tasks.  I tried setting the subproject files as readonly in both the file system and in the Insert Subproject Information dialog in MS Project.   I had absolutely no luck in getting dialogs to pop up.   Then I tried a classic "File in Use" scenario.  I first opened one of the subproject files from another user account and then opened the master project and ran our visualization application.  Sure enough, I got a "File In Use" dialog that gave me the choices of opening "Read only" or of doing "Notify".   The DisplayAlerts=False did not suppress these dialog boxes, most likely because they're coming directly from MS Windows rather than from MS Project.   However, I discovered that checking the "read-only" box on the Advanced tab of the Insert Subproject Information dialog made the problem go away.  So, telling the master project to open the subprojects as read only prevents Windows from trying to block a potential race condition, so it does not issue the "File In Use" dialog.  Does this make sense?   Maybe this is why Microsoft put the read-only check box there in the first place!


    ...Jim Black


    Tuesday, July 1, 2014 8:32 PM
  • Jim,

    Better man huh, well, I don't know about that. Let's just say I'm a good egg who's hoping he won't crack, it would just be too messy.

    You're right in that the display alerts only applies to alerts generated by Project. And yes, if the file is opened read only, then there will be no conflict in the event two users attempt to edit and save the same file at the same time.

    John

    • Marked as answer by Jim Black CG Tuesday, July 1, 2014 11:03 PM
    Tuesday, July 1, 2014 10:58 PM