Reputation: 574
I'm working on an app that has to use two more excel files for its function. Names of those files change every day so I decided that both of those files are going to be opened from cells that contain functions to change the name based on the date like this.
Workbooks.Open Range("C2")
Windows("App.xlsm").Activate
Workbooks.Open Range("C16")
Now the problem is that I don't know how to switch between the books that I've opened. Normally I'd use something like this:
Windows("A.xlsx").Activate
But I clearly can't do that now. My idea was to activate App.xlsm and then activate a workbook written in the cell that I used like his:
Windows(Workbooks("App.xlsm").Sheets("Pom").Range("C16").Value).Activate
However that doesn't work. Now I'm not sure whether my code is wrong or whether this method just isn't possible. Can someone help me please ?
Upvotes: 1
Views: 104
Reputation: 12167
Use variables to have a handle on the workbooks
Dim wb1 as workbook
dim wb2 as workbook
set wb1 = Workbooks.Open (Range("C2"))
set wb2 = Workbooks.Open (Range("C16"))
' Activate wb1
wb1.activate
' or activate wb2
wb2.activate
Upvotes: 2