读取Excel数据到数组中:
Function ReadExcel(sFileName,sSheetName)
Dim oExcel
Dim oRange
Dim arrRange
'Open the file and set the sheet
On Error Resume Next
Set oExcel = CreateObject("Excel.Application")
oExcel.Workbooks.Open(sFileName)
Set oRange=oExcel.Worksheets(sSheetName).UsedRange
If Err.Number <> 0 Then
ReadExcel = Array("Error")
Exit Function
End If
On Error Goto 0
'Cast excel data into a two-dimentional array
arrRange = oRange.Value
oExcel.WorkBooks.Item(1).Close
Set oRange = Nothing
oExcel.Quit
Set oExcel = Nothing
'return the arrRange and then return to the function
ReadExcel = arrRange
End Function
如何把一个Excel中的Sheet页数据拷贝到另外一个Excel的Sheet页中:
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'Paste =xlValues
objWorkbook1.Save
objWorkbook2.Save
objWorkbook1.Close
objWorkbook2.Close
objExcel.Quit
set objExcel=nothing作者: deadhunter 时间: 2010-9-20 13:42
还是不明白,能举个excel中生成二维折线图的例子吗?作者: skyzhu 时间: 2010-9-20 14:29
参考3#给的代码,结合录制EXCEL宏(VBA)代码
写成VBS