Get filename

T

Tang

i use getopenfilename to get a excel file and open it, and copy certain
range within 2 files.

my problem is i don't know how to switch within 2 windows.

i try to use workbook(filename).activate, but the filename variable include
the path as well.

regards
 
J

JE McGimpsey

One way:

Dim wbBook1 As Workbook
Dim wbBook2 As Workbook
Dim vFileName As Variant
Set wbBook1 = ActiveWorkbook
vFileName = Application.GetOpenFilename
If vFileName = False Then Exit Sub
Set wbBook2 = Workbooks.Open(Filename:=vFileName)

Then use

wbBook2.Activate

and

wbBook1.Activate

to switch.
 
Top