deadhunter 发表于 2010-9-10 11:14:45

请教VBS在excel中生成二维折线图的例子?

本帖最后由 deadhunter 于 2010-9-20 13:43 编辑

请教VBS在excel中生成二维折线图的例子?

lantianwei 发表于 2010-9-10 17:30:23

Set oExcel = GetObject(,"Excel.Application")
是否问这个?

TIB 发表于 2010-9-10 21:15:33

参考一下VBA编程吧,下面是一些例子:

读取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:11

还是不明白,能举个excel中生成二维折线图的例子吗?:lol

skyzhu 发表于 2010-9-20 14:29:22

参考3#给的代码,结合录制EXCEL宏(VBA)代码
写成VBS
页: [1]
查看完整版本: 请教VBS在excel中生成二维折线图的例子?