Private Sub Command1_Click()
Dim i As Long
Dim j As Long
Dim myData(, ) As Long
Dim xlApp, WS, WB
Set xlApp = CreateObject("Excel.Application")
Set WB = xlApp.WorkBooks.Add
Set WS = WB.Sheets()
For i = To
For j = To
WS.Cells(i + , j + ).Value = myData(i, j) '写入第i+1行,第j+1列
Next j
Next i
xlApp.Visible = True
Set xlApp = Nothing
Set WS = Nothing
Set WB = Nothing
End Sub
上面只是读取出来,如果要写入操作,也可以:
Private Sub Command1_Click()
Dim i As Long
Dim j As Long
Dim myData(, ) As Long
Dim xlApp
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
xlApp.WorkBooks.Open ("d:\123.xls")
xlApp.WorkSheets("Sheet1").Activate
For i = To
If i > Then xlApp.WorkSheets("Sheet2").Activate
For j = To
xlApp.Cells(i + , j + ).Value = myData(i, j) '写入第i+1行,第j+1列
Next j
Next i
'保存
'xlApp.ActiveWorkbook.Save
'另存
'xlApp.ActiveWorkbook.SaveAs "d:\456.xls"
'显示出来
'xlApp.Visible = True
'关闭
'xlApp.WorkBooks.Close
'xlApp.Quit
Set xlApp = Nothing
End Sub