子测试() Dim Target_Workbook As Workbook Dim Source_Workbook As Workbook Dim Target_Path As String Target_Path =" Sample.xlsx" 设置Target_Workbook = Workbooks.Open(Target_Path) 设置Source_Workbook = ThisWorkbook Source_data = Source_Workbook.Sheets(1).Range(" A1:Y74")。复制 Target_Workbook.Sheets(1).Range(" A1&#34)激活。 Source_Workbook.Save Target_Workbook.Save Target_Workbook.Close False MsgBox"任务已完成" 结束子
答案 0 :(得分:0)
使用下面的代码,填充源和目标excel文件名并调用此代码
Sub CopyWorkbook(Sourceworkbook, TargetWorkbook)
Dim sh As Worksheet, wb As Workbook, wbSource As Workbook
Dim SourcefileName As String
SourcefileName = Sourceworkbook
Set wbSource = Workbooks.Open(Sourceworkbook)
Set wb = Workbooks(TargetWorkbook)
For Each sh In Workbooks(SourcefileName).Worksheets
sh.Copy After:=wb.Sheets(wb.Sheets.count)
Next sh
wbSource.Close
End Sub
例如TargetWorkbook =" TwoSheet_Compare V2.0.xlsm"和 SourceWorkbook =" sourceFile.xlsx"