none
If View exists then exit sub RRS feed

  • Question

  • In Microsoft Project 2010, I am creating a VBA Macro to see what is past due each time the project is open via msgbox ‘yes,no’. In the Macro I created a new view ‘PastDueView’, however, the macro will not run more than once, because the view was created in the project the first time the Macro was run and I get a run time error.  How do I create an If statement that states If the ‘PastDueView’ exists to skip creating the ‘PastDueView’ and continue with the Macro?

    • Moved by Mark Liu-lxf Thursday, November 8, 2012 6:11 AM (From:Visual Basic General)
    Wednesday, November 7, 2012 9:25 PM

Answers

  • Hi MacroHelp,

    are you looking for someting like this?

    Sub CheckView()
    Dim Vw As View
    For Each Vw In ActiveProject.Views
     If Vw.Name = "XXX" Then
        MsgBox "exists"
     End If
    Next
    End Sub

    Regards
    Barbara

    • Marked as answer by Cindy_M Wednesday, February 7, 2018 7:03 PM
    Thursday, November 8, 2012 8:11 AM
    Moderator

All replies

  • I think that a better forum to ask this is would be one of the ones listed at social.technet.microsoft.com/Forums/en-US/category/projectserver2010,projectprofessional2010

    - this forum is for VB.NET, which is different from VBA.

    --
    Andrew

    • Proposed as answer by Frank L. Smith Wednesday, November 7, 2012 11:07 PM
    Wednesday, November 7, 2012 9:47 PM
  • I am not sure  how to do that.  If you tell me how I will be more that happy to move the question.
    Wednesday, November 7, 2012 10:02 PM
  • Hi MacroHelp,

    Welcome to the MSDN forum.

    I’d like to move this thread to the forum (Project Standard and Professional General Questions and Answers) suggested by Andrew. It will cost a little time to involve the members in this forum. I appreciate your patience.

    Have a nice day.


    Mark Liu-lxf [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, November 8, 2012 6:09 AM
  • Hi MacroHelp,

    are you looking for someting like this?

    Sub CheckView()
    Dim Vw As View
    For Each Vw In ActiveProject.Views
     If Vw.Name = "XXX" Then
        MsgBox "exists"
     End If
    Next
    End Sub

    Regards
    Barbara

    • Marked as answer by Cindy_M Wednesday, February 7, 2018 7:03 PM
    Thursday, November 8, 2012 8:11 AM
    Moderator