51Testing软件测试论坛
标题:
如何对多个excel表格进行拷贝呢?
[打印本页]
作者:
素还真
时间:
2010-5-4 10:32
标题:
如何对多个excel表格进行拷贝呢?
比如我要把b.xls的sheet1拷贝到a.xls的sheet2,
这样要如何操作呢?
作者:
素还真
时间:
2010-5-4 11:29
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
作者:
TIB
时间:
2010-5-4 11:43
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
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2