none
VBA Open Project file in specific view RRS feed

  • Question

  • Is there a way to open an MSProject file in a specific view via VBA?  I am opening the file in the backgroud to loop through the tasks from Excel and the file is opten saved in a view that has a date range filter.  I don't want the users to be prompted for a date range since using a

    For Each tsk in proj.Task

    ignores the filter anyway.

    Thanks!

    Thursday, February 16, 2012 2:43 PM

Answers

  • Hi,

    I see, to apply a view like Gantt Chart could avoid the pops up date range filter. You could achieve that by following VBA code:

    Private Sub Project_Open(ByVal pj As Project)
    ViewApply Name:="Gantt Chart"
    
    End Sub
    Let me know if there's anything unclear please.
    Best Regards,

    Forrest Guo | MSDN Community Support | Feedback to us

    Wednesday, February 22, 2012 1:41 PM
    Moderator

All replies

  • Hi Puck312,

    Thank you for posting.

    After reading your post, I am still not clear about your problem.

    1. What do you mean open an MSProject file in a specific view?

    2. Can you show us more code about your problem?

    3. What is the version of your MS project?

    4. How did you get promopted date range for the users?

    5. Can you show us the reproducible steps list about the problem?

    I use the following vba code snippet and didn't get the prompt date range:

    Sub test()
    Dim tsk As Task
    For Each tsk In ActiveProject.Tasks
    MsgBox tsk.Name
    Next
    End Sub

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us

    • Edited by Bruce Song Monday, February 20, 2012 9:06 AM
    Monday, February 20, 2012 9:05 AM
  • The users apply a specific (custom) view when they use the file (similar to gantt view but has custom filter that includes prompting for a date range so it only shows items that open and close during the date range).  This is the view that they always use and save the file this way.  So, when I go to open the file, that is the way that it tries to open and it prompts me for a date range.

    The prompt comes when you do a app.FileOpen command.  It does not seem to be affect by doing a app.DisplayWarnings = False prior to opening the file. 

    Since the prompt comes up on open, I cannot just switch the applied view after opening because the prompt has already occured.  The only way that I can think of to avoid the prompt is to open the file in a specific view (say: Gantt view with no filter applied)
    Tuesday, February 21, 2012 12:06 AM
  • Puck312,I will help you involve others to help you. There might be some delay about the response. Appreciate your patience.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, February 22, 2012 8:42 AM
  • Hi,

    I see, to apply a view like Gantt Chart could avoid the pops up date range filter. You could achieve that by following VBA code:

    Private Sub Project_Open(ByVal pj As Project)
    ViewApply Name:="Gantt Chart"
    
    End Sub
    Let me know if there's anything unclear please.
    Best Regards,

    Forrest Guo | MSDN Community Support | Feedback to us

    Wednesday, February 22, 2012 1:41 PM
    Moderator