分享

VB读取excel表中的数据

 hdzgx 2019-12-06

在“工程”的“引用”中选择“microsoft excel 11.0”,"microsoft excel 11.0"看版本而定
Dim xlApp As New Excel.Application
Dim xlBook As New Excel.Workbook
Dim xlSheet As New Excel.Worksheet

Private Sub Command1_Click()
On Error Resume Next
   '后台进程运行excel程序,并得到该工作簿
   Set xlBook = xlApp.Workbooks.Open("f:/1.xls")
   xlApp.Visible = False
   '获得该工作簿的“sheet1”表
   Set xlSheet = xlBook.Sheets("sheet1")
  
   xlSheet.Select
   '抽取b2格子的数据并赋值给text1.text
   text1.Text = xlSheet.Range("b2")
   '释放资源,顺序到过来的,表》》簿》》应用程序
   Set xlSheet = Nothing
   Set xlBook = Nothing
   xlApp.Quit
   Set xlApp = Nothing
End Sub

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多