I need to switch between 2 open files in a macro. I know the name of one
file but not the other. What code can I use to activate the workbook that I
don't know the name of?
I need to switch between 2 open files in a macro. I know the name of one
file but not the other. What code can I use to activate the workbook that I
don't know the name of?
Maybe
Activewindow.ActivateNext
but it wouldn't be my first choice as it depends on there being only two
workbooks open.
Can you use the macros in the first workbook to open the second during
execution? Since you don't know the file name, I assume the user has to open
the second book.
Sub test()
Dim wkbTest As Workbook
Dim varFName As Variant
varFName = Application.GetOpenFilename
If varFName = False Then End
Set wkbTest = Workbooks.Open(Filename:=varFName)
End Sub
Then you can use the object variable, wkbTest (change variable name if you
like) to refer to the second book.
wkbTest.Worksheets("Sheet1").Range("A1").Value = 5
"Lynn" wrote:
> I need to switch between 2 open files in a macro. I know the name of one
> file but not the other. What code can I use to activate the workbook that I
> don't know the name of?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks