none
Substitute Variable for Literal in Project VBA RRS feed

  • Question

  • I have the following code in a Project VBA program:  Windows("MyFileName").Visible = False. I need to substitute a variable for the literal file name. The Windows object does not seem to support such a substitution. I've tried various forms of strings with quotes, and none work. Does anybody know how to use a variable with this object?

    RobVV

    Friday, October 18, 2013 11:23 PM

Answers

  • Try:

    Sub test()
    Dim Nam As String
        Nam = "Window Caption.mpp"
        Windows(Nam).Visible = False
    End Sub


    Rod Gill

    The one and only Project VBA Book

    Rod Gill Project Management

    • Proposed as answer by John - Project Saturday, October 19, 2013 1:50 AM
    • Marked as answer by RobVV Saturday, October 19, 2013 2:53 PM
    Friday, October 18, 2013 11:53 PM
    Moderator
  • Thanks, Rod. If the literal name is known, then the substitution you suggest works well. In my case, the literal name was not known prior to run time. When I tried to build the name from strings and double quotes, I got a "subscript out of range" error from the Windows statement.

    So, I used your idea in the following way. After I opened the file in the program, I trapped its name in a string. I dropped the extension and used the remaining file name in the Windows statement. It worked. Thanks, again.

    Dim Test As String
    Dim EndPt As Integer
    Test = <MyFileName>.Name
    EndPt = InStrRev(test, ".mpp", -1, vbTextCompare)
    Test = Left(Test, EndPt - 1)
    Windows(Test).Visible = False


    RobVV

    • Marked as answer by RobVV Saturday, October 19, 2013 2:53 PM
    Saturday, October 19, 2013 2:51 PM

All replies

  • Try:

    Sub test()
    Dim Nam As String
        Nam = "Window Caption.mpp"
        Windows(Nam).Visible = False
    End Sub


    Rod Gill

    The one and only Project VBA Book

    Rod Gill Project Management

    • Proposed as answer by John - Project Saturday, October 19, 2013 1:50 AM
    • Marked as answer by RobVV Saturday, October 19, 2013 2:53 PM
    Friday, October 18, 2013 11:53 PM
    Moderator
  • Thanks, Rod. If the literal name is known, then the substitution you suggest works well. In my case, the literal name was not known prior to run time. When I tried to build the name from strings and double quotes, I got a "subscript out of range" error from the Windows statement.

    So, I used your idea in the following way. After I opened the file in the program, I trapped its name in a string. I dropped the extension and used the remaining file name in the Windows statement. It worked. Thanks, again.

    Dim Test As String
    Dim EndPt As Integer
    Test = <MyFileName>.Name
    EndPt = InStrRev(test, ".mpp", -1, vbTextCompare)
    Test = Left(Test, EndPt - 1)
    Windows(Test).Visible = False


    RobVV

    • Marked as answer by RobVV Saturday, October 19, 2013 2:53 PM
    Saturday, October 19, 2013 2:51 PM