Workbooks with Variable name

  • I am unable to work with Workbooks which name is based on a Variable

    1. Sub test2()
    2. Dim MyFile As String
    3. MyFile = "Justin Dashboard 2019"
    4. Workbooks(MyFile).Active
    5. End Sub

    This gives me the error "Object doesn't support this property or method"

    Of course I need a dynamic variable which will be changed based on other variables etc... in the future.
    but for now, I am not even able to go further unless I put

    1. Workbooks("Justin Dashboard 2019").Active

    just without a variable.
    This is blocking my work

    Any help would be of big help!
    Thank you in advance


  • "Active"is causing the error, it is not a property of "Workbooks'. Try

    1. Workbooks(myFile).Activate

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Thanks for correcting. This has proven that the variable works and that I have mistaken in other properties and functions.
    Whish is leading me to a solution
    Thanks for helping!