How do i copy one excel file to another excel file using VBA How do i mention the paths of the two excel files?
This is what i found on the internet:
ActiveSheet.Move After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count)
This is what i saw but im unable to make it can anyone tell me the way i can make it?
I have to copy开发者_StackOverflow中文版 all the rows and columns of one excel file to the end of the other excel file.
How do I make it?If you want to move (or copy) worksheets from a workbook to another, you have to set the other workbook in a var. Let me give you an example:
Dim oNewWB as Workbook
Dim oCurWB as Workbook
'Store active workbook in a var
Set oCurWB = ActiveWorkbook
'Open a new workbook
Set oNewWB = Application.Workbooks.Open(<pathToWorkbookHere>)
'Move "Sheet1" from the current workbook to new one
oCurWB.Sheets("Sheet1").Move After:=oNewWB.Sheets(oNewWB.Sheets.Count)
[EDIT] New piece of code as suggested by Maverik
Let's say you want to copy every sheet in your workbook to the new one:
Dim oNewWB as Workbook
Dim oCurWB as Workbook
Dim Sheet as Worksheet
'Store active workbook in a var
Set oCurWB = ActiveWorkbook
'Open a new workbook
Set oNewWB = Application.Workbooks.Open(<pathToWorkbookHere>)
For Each Sheet In oCurWB.Sheets
'Move "Sheet1" from the current workbook to new one
Sheet.Move After:=oNewWB.Sheets(oNewWB.Sheets.Count)
Next Sheet
HTH
精彩评论