Copy a Sheet without physically opening the file

  • Thread starter Thread starter Michael Kintner
  • Start date Start date
M

Michael Kintner

Is there a way that I can copy a sheet from one file to the next without
having to use:

Workbooks.Open "Filename", True, True

My problem is I wish to copy Sheet1 from one file to the next, then close
the original file. Currently I can make it work but I do not know how to
get back to the file once I perform the copy sheet command. Note: The
filename may change.

Thank you for your help in advance!!! (smile)

Mike
 
Hi Michael

Set Wb2 = Workbooks.Open("C:\test.xls")
You can always use Wb2 in your code to refer to the sheet you have open


Sub test()
Dim Wb1 As Workbook
Dim Wb2 As Workbook
Application.ScreenUpdating = False
Set Wb1 = ActiveWorkbook
Set Wb2 = Workbooks.Open("C:\test.xls")
Wb2.Worksheets(1).copy after:= _
Wb1.Sheets(Wb1.Sheets.Count)
Wb2.Close False
Application.ScreenUpdating = True
End Sub
 
Back
Top