任务描述 :把 source.xls 中的某个sheet 拷贝到 target.xls中去(注意,删除了source.xls中的sheet)。 目标文件名、原文件名、拷贝的sheet名存在当前xls vba文件的A2 B2 C2单元格中 。
Sub 按钮1_Click()
Dim source As Workbook
Dim target As Workbook
Dim name1 As String
Dim name2 As String
Dim sheetname As String
Application.DisplayAlerts = False
tname = ThisWorkbook.Sheets(1).[A2]
sname = ThisWorkbook.Sheets(1).[B2]
sheetname = ThisWorkbook.Sheets(1).[C2]
Set target = Workbooks.Open(ThisWorkbook.Path & "\" & tname)
Set source = Workbooks.Open(ThisWorkbook.Path & "\" & sname)
target.Sheets(sheetname).Delete
source.Sheets(sheetname).Copy after:=target.Sheets(target.Sheets.Count)
target.Save
target.Close
source.Close
Application.DisplayAlerts = True
End Sub