VB 读excel 数据(用commondialog)
这个是我写的 我也引用部件了,excel也引入了但是只能显示对话框
不能显示msgbox 我想可能是没有进行excel读入操作
请高手看看哪里的问题
Dim bb(1000,1000) as Double
Private Sub Command1_Click()
Me.AutoRedraw = True
Dim xlsApp As Excel.Application
Dim xlsworkbook As Excel.Workbook
Dim xlssheet As Excel.Worksheet
Dim sFile As String
On Error GoTo ErrHandler
CommonDialog1.Filter = "ALL Files(*.*)|*.*|" & "Text Files(*.xls)|*.xls|"
CommonDialog1.FilterIndex = 2
CommonDialog1.ShowOpen
If CommonDialog1.FileName = "" Then
Exit Sub
End If
sFile = CommonDialog1.FileName
Set xlsApp = CreateObject("Excel.Application")
Set xlsworkbook = xlsApp.Workbooks.Open(sFile)
xlsApp.Visible = True
Set xlssheet = xlsworkbook.Worksheets("Sheet1")
xlssheet.Activate
Dim i, j As Integer
For i = 0 To xlssheet.UsedRange.Rows.Count - 1
For j = 0 To xlssheet.UsedRange.Columns.Count - 1
b(i, j) = xlssheet.Cells(i, j)
Next j
Next i
Set xlssheet = Nothing
Set xlsworkbook = Nothing
Set xlsApp = Nothing
MsgBox "数据导入完毕!"
ErrHandler:
Exit Sub
End Sub