macro to set current workbook as variable and set as active later

  • I need help with a macro. When I run the macro, I need to set the current workbook as a variable. I want to then call that variable later.
    Here is what I have and it doesn't work. I have two workbooks open. If I name them in the macro I can see it switc focus to each one. If I try to pass in a variable name, I get errors. Any ideas?


    Code
    Sub switchWorkbook() 
    Dim WB As Workbook
    Set WB = ThisWorkbook
    Windows("FEB PROJECT REPORT.CSV").Activate
    Windows(WB).Activate
    End Sub
  • Re: macro to set current workbook as variable and set as active later


    Maybe making it a string instead...like this:


    Code
    Sub switchWorkbook()
        Dim WB As String
        WB = ThisWorkbook.Name
        Windows("FEB PROJECT REPORT.CSV").Activate
        Windows(WB).Activate
    End Sub

Participate now!

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