VB怎么读取不了excel中的数据?
PrivateSubCommand3_Click()DimExAppAsNewExcel.ApplicationDimExbAsExcel.WorkbookDimExsh...
Private Sub Command3_Click()
Dim ExApp As New Excel.Application
Dim Exb As Excel.Workbook
Dim Exsh As Excel.Worksheet
Dim arr(6, 6) As Integer
ExApp.Workbooks.Open "c:\Documents and Settings\abc.xls" '
Set Exb = ExApp.Workbooks(1)
Set Exsh = Exb.Worksheets("Sheet1")
For i = 1 To 6
For j = 1 To 6
arr(i, j) = Exsh.Cells(i, j)
Next j
Next i
For i = 1 To 6
If arr(i, 1) = Combo1.Text And arr(i, 2) = Combo2.Text Then
Text1.Text = arr(i, 3)
Text2.Text = arr(i, 4)
Text3.Text = arr(i, 5)
Text4.Text = arr(i, 6)
End If
Next i
ExApp.Workbooks.Close
ExApp.Quit
Set ExApp = Nothing
End Sub 展开
Dim ExApp As New Excel.Application
Dim Exb As Excel.Workbook
Dim Exsh As Excel.Worksheet
Dim arr(6, 6) As Integer
ExApp.Workbooks.Open "c:\Documents and Settings\abc.xls" '
Set Exb = ExApp.Workbooks(1)
Set Exsh = Exb.Worksheets("Sheet1")
For i = 1 To 6
For j = 1 To 6
arr(i, j) = Exsh.Cells(i, j)
Next j
Next i
For i = 1 To 6
If arr(i, 1) = Combo1.Text And arr(i, 2) = Combo2.Text Then
Text1.Text = arr(i, 3)
Text2.Text = arr(i, 4)
Text3.Text = arr(i, 5)
Text4.Text = arr(i, 6)
End If
Next i
ExApp.Workbooks.Close
ExApp.Quit
Set ExApp = Nothing
End Sub 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询