如何对多个excel表格进行拷贝呢?
比如我要把b.xls的sheet1拷贝到a.xls的sheet2,这样要如何操作呢? Command15_Click
Private Sub Command15_Click()
Set objExcel = CreateObject("Excel.Application")
Set objBook1 = objExcel.Workbooks.Open("d:\m.xls")
Set objBook2 = objExcel.Workbooks.Open("d:\n.xls")
objExcel.Visible = True
Set objSheet1 = objBook1.Sheets("Sheet1")
Set objSheet2 = objBook2.Sheets("Sheet1")
objSheet1.Copy objSheet2
MsgBox "OK"
End Sub
使用这个发现,会建立一个新的Sheet1(2),没办法覆盖原来的Sheet1 Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook1= objExcel.Workbooks.Open("D:\1.xls")
Set objWorkbook2= objExcel.Workbooks.Open("D:\2.xls")
objWorkbook1.Worksheets("Sheet1").UsedRange.Copy
objWorkbook2.Worksheets("Sheet2").Range("A1").PasteSpecial
objWorkbook1.Save
objWorkbook2.Save
objWorkbook1.Close
objWorkbook2.Close
objExcel.Quit
set objExcel=nothing
页:
[1]