Get filename

  • Thread starter Thread starter Tang
  • Start date Start date
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
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top