请教请问如何用vb提取excel表格中的数据
展开全部
首先需要知道你要引用的数据在Excel中的位置,然后在VB里面引用Excel,
然后打开Excel文件读数据
Dim scxls As Excel.Application
Dim scbook As Excel.Workbook
Dim scsheet As Excel.Worksheet
‘Set scxls = CreateObject("excel.application")
‘Set scbook = scxls.Workbooks.Add
Set scbook = scxls.Workbooks.open("c:\1.xls")
Set scsheet = scbook.Worksheets(1)
‘scsheet.Cells(1, 2) = "1111" ’写入数据
a=scsheet.Cells(1, 2) '读取数据
Set scbook = Nothing
Set scxls = Nothing
‘scxls.Visible = True ’显示Excle
数据较多,且有规律可循时,请使用循环语句
展开全部
1、用VB 打开EXCEL 文件
2、遍历sheets和cells
Dim xlApp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Private Sub Command1_Click()
Set xlApp = New Excel.Application
xlApp.Visible = True
Set xlbook = xlApp.Workbooks.Open("d:\hao\1.xls")
For i = 1 To xlbook.Worksheets.Count
Set xlsheet = xlbook.Worksheets(i)
aa=xlsheet.Cells(1, 1)
Next
End Sub
2、遍历sheets和cells
Dim xlApp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Private Sub Command1_Click()
Set xlApp = New Excel.Application
xlApp.Visible = True
Set xlbook = xlApp.Workbooks.Open("d:\hao\1.xls")
For i = 1 To xlbook.Worksheets.Count
Set xlsheet = xlbook.Worksheets(i)
aa=xlsheet.Cells(1, 1)
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询