展开全部
Public Function Read_Excel(ByVal sFile As String) As ADODB.Recordset
On Error GoTo fix_err
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim sconn As String
rs.CursorLocation = adUseClient
rs.CursorType = adOpenKeyset
rs.LockType = adLockBatchOptimistic
sconn = "DRIVER=Microsoft Excel Driver (*.xls); " & "DBQ= " & sFile
rs.Open "SELECT * FROM [sheet1$] ", sconn
Set Read_Excel = rs
Set rs = Nothing
Exit Function
fix_err:
Debug.Print Err.Description + " " + _
Err.Source, vbCritical, "Import "
Err.Clear
End Function
Private Sub Command1_Click()
Set dgData.DataSource = Read_Excel(App.Path & "\ " & "test.xls ")
Set obj = Nothing
End Sub
在网上查询到的,试试这个怎样
On Error GoTo fix_err
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim sconn As String
rs.CursorLocation = adUseClient
rs.CursorType = adOpenKeyset
rs.LockType = adLockBatchOptimistic
sconn = "DRIVER=Microsoft Excel Driver (*.xls); " & "DBQ= " & sFile
rs.Open "SELECT * FROM [sheet1$] ", sconn
Set Read_Excel = rs
Set rs = Nothing
Exit Function
fix_err:
Debug.Print Err.Description + " " + _
Err.Source, vbCritical, "Import "
Err.Clear
End Function
Private Sub Command1_Click()
Set dgData.DataSource = Read_Excel(App.Path & "\ " & "test.xls ")
Set obj = Nothing
End Sub
在网上查询到的,试试这个怎样
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询