Workbooks with Variable name

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


    Code
    Sub test2()
    Dim MyFile As String
    MyFile = "Justin Dashboard 2019"
    Workbooks(MyFile).Active
    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



    Code
    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


    Giorgio

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

    Code
    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!

  • You're welcome

    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.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!