求VB中与EXCEL表连接,从EXCEL表中读数据
求VB中与EXCEL表连接,从EXCEL表中读数据,数据在EXCEL中是矩阵的形式,在VB中是二维数组。高手们帮帮忙吧
[解决办法]
Option ExplicitDim ex As Excel.ApplicationDim wb As Excel.WorkbookDim sh As Excel.WorksheetPrivate Sub Form_Load()On Error GoTo err1Set ex = New Excel.ApplicationSet wb = ex.Workbooks.Open("C:\Documents and Settings\yong.ZZY\桌面\book1.xls")Set sh = wb.Sheets(1)Debug.Print sh.NameDim arr(1, 1)Dim i As Integer, j As IntegerFor i = 1 To 2 For j = 1 To 2 arr(i - 1, j - 1) = sh.Cells(i, j).Value Debug.Print arr(i - 1, j - 1) Next jNext iExit Suberr1:Set sh = NothingSet wb = NothingSet ex = NothingDebug.Print Err.DescriptionEnd SubPrivate Sub Form_Unload(Cancel As Integer)Set sh = NothingSet wb = NothingSet ex = NothingEnd Sub
[解决办法]
忘了关闭了
wb.Close
ex.Quit
[解决办法]
Dim strFileName As String strFileName = GetExcelFileName("客户资料表", dlg) Dim objApp As New Excel.Application Dim exBook As Excel.Workbook Dim exSheet As Excel.Worksheet Set exBook = objApp.Workbooks.Open(strFileName) Set exSheet = exBook.Worksheets(1) //存放在varCustomerList中 Dim varCustomerList As Variant varCustomerList = exSheet.UsedRange.Value
[解决办法]
http://blog.csdn.net/vbman2003/archive/2007/10/25/1843645.aspx