vB编程VB源码 VB读取EXCEL工作薄某个表中数据 ADODB.Recordset

前端之家收集整理的这篇文章主要介绍了vB编程VB源码 VB读取EXCEL工作薄某个表中数据 ADODB.Recordset前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Private Sub Form_Load()
Dim RS As ADODB.Recordset
Set RS = GetExcelRs(App.Path & "\book1.xls")
MsgBox RS.RecordCount
MsgBox RS(0)
RS(0) = Timer
RS.Update
RS.Close
End Sub

'┏〓〓〓〓〓〓〓〓〓 GetExcelRs,start 〓〓〓〓〓〓〓〓〓┓
'[简介]:
'VB读取EXCEL工作薄某个表中数据
Function GetExcelRs(ByVal sFile As String,Optional ExcelSheetName As String = "sheet1",Optional ErrInfo As String) As ADODB.Recordset
   '[mycode_id:2025],edittime:2011-9-7 下午 02:15:41
   On Error GoTo Err
   Dim RS As ADODB.Recordset
   Set RS = New ADODB.Recordset
   Dim ConnStr As String
   ConnStr = "DRIVER=Microsoft Excel Driver (*.xls);" & "DBQ=" & sFile & ";ReadOnly=False"
   
   RS.Open "SELECT * FROM [" & ExcelSheetName & "$]",ConnStr,1,3
   
   Set GetExcelRs = RS
   Set RS = Nothing
   
   Exit Function
   Err:
   ErrInfo = Err.Description
   MsgBox ErrInfo
End Function
'┗〓〓〓〓〓〓〓〓〓  GetExcelRs,end  〓〓〓〓〓〓〓〓〓┛

猜你在找的VB相关文章