ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to copy a sheet from a workbook to another in different folder (https://www.excelbanter.com/excel-programming/344289-how-copy-sheet-workbook-another-different-folder.html)

Kurt

How to copy a sheet from a workbook to another in different folder
 
Happy Holloween!

I'd like to copy in VBA a sheet from one workbook to another workbook that
is located in different folder.

Thanks!

Kurt


Jim Thomlinson[_4_]

How to copy a sheet from a workbook to another in different folder
 
This also copies a range from one book to the other but it should work for
you with a little tweaking...

Sub Test()
Dim wbkSource As Workbook
Dim wbkDestination As Workbook
Dim wksSource As Worksheet
Dim wksDestination As Worksheet
Dim rngSource As Range
Dim rngDestination As Range

'Set your source
Set wbkSource = ThisWorkbook
Set wksSource = wbkSource.Sheets("Sheet1")
Set rngSource = wksSource.Cells

'Set your destination
On Error GoTo OpenBook
Set wbkDestination = Workbooks("ThatBook.xls")
On Error GoTo 0
Set wksDestination = wbkDestination.Sheets("Sheet1")
Set rngDestination = wksDestination.Range("A1")

'You now have all of your souce and destination objects

wksSource.Copy wksDestination 'Copy the sheet
rngSource.Copy rngDestination 'Copy a range

Exit Sub

OpenBook:
Set wbkDestination = Workbooks.Open("C:\Thatbook.xls")
Resume Next
Exit Sub

End Sub

--
HTH...

Jim Thomlinson


"kurt" wrote:

Happy Holloween!

I'd like to copy in VBA a sheet from one workbook to another workbook that
is located in different folder.

Thanks!

Kurt



All times are GMT +1. The time now is 11:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com