数据导入问题
刚开始学Vb,怎么把Excel中的数据导入到VB中的数组变量里面呢?这个看了一些书,一直没看到解决的办法。
Option Base 1 Private Sub Command1_Click() Dim a As Excel.Application Dim b As Excel.Workbook Dim c As Excel.Worksheet Set a = CreateObject("Excel.Application") Set b = a.Workbooks.Add Set c = b.Sheets(1) c.Activate For i = 1 To 10 For j = 1 To 10 c.Cells(i, j) = "ABC" Next j Next i a.ActiveWorkbook.SaveAs ("C:\TMB\123.xls") a.Workbooks.Close End Sub
Private Sub Command2_Click() Dim a As Excel.Application Dim d() As String, E As String ReDim d(10, 10) Set a = CreateObject("Excel.Application") With a .Workbooks.Open "C:\TMB\123.xls" '要打開的 xls 檔案 For i = 1 To 10 For j = 1 To 10 E = a.Worksheets("Sheet1").Cells(i, j).Value d(i, j) = E Next j Next i .Quit End With End Sub