MrExcel Publishing
Your One Stop for Excel Tips & Solutions

open sheet in same excel workbook

Posted by oli on January 09, 2002 5:12 PM

ok i have a little problem, i want to open an excel sheet with a dos batch file (ex: c:\...\excel.exe file.xls) in the same excel workbook that is already open, but it doesn't work, it always open another excel workbook instead. it works if if do it with the run menu (from start in windows) if i type c:\file.xls it will open in the same excel workbook. is it possible to do what i want or does it exist a program launcher (like the "run" in windows) that will open the file in the same workbook

Posted by Henry Collet on January 10, 2002 2:39 AM

You can do it in a three step method. Open the file (file2) into a new workbook. Copy the worksheet (sheet1) which you want into your existing workbook (file1), and then close the second workbook, discarding the changes. See code below.

Workbooks.Open Filename:="c:\file2.xls"
Sheets("Sheet1").Move After:=Workbooks("file1.xls").Sheets(1)
Workbooks("file2.xls").Close SaveChanges:=False