加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-16 22:48:44 所属栏目:大数据 来源:网络整理
导读:Private Sub Form_Load()Dim RS As ADODB.RecordsetSet RS = GetExcelRs(App.Path "book1.xls")MsgBox RS.RecordCountMsgBox RS(0)RS(0) = TimerRS.UpdateRS.CloseEnd Sub'┏〓〓〓〓〓〓〓〓〓 GetExcelRs,start 〓〓〓〓〓〓〓〓〓┓'[简介]:'VB读取EX
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  〓〓〓〓〓〓〓〓〓┛

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读