如何在VB6中抓取又名显示Excel文档的所有内容
我编写了一个程序来读取 Excel 文档并将其显示在消息框中。但是,问题是,我想将其全部废弃(即显示到 messageBox),而不知道要选择哪一行或哪列。我写了这段代码:
Private Sub Command1_Click()
On Error GoTo Err
StartExcel
Set ExcelWBk = Excel.Workbooks.Open(App.Path & "\Dataku.xls")
Set ExcelWS = ExcelWBk.Worksheets(1)
With ExcelWS
Dim i As Integer
Dim strData As String
For i = 1 To 5
strData = strData & .Cells(i, 1) & vbCrLf
Next i
End With
MsgBox strData
CloseWorkSheet
ClearExcelMemory
Exit Sub
Err:
ClearExcelMemory
End Sub
但它仅返回该列(第 1 列)的数据。我需要读取整个 Excel 文件。
i made a program to read an excel document and display it on a messageBox. but, the thing is, i want to scrap aka display all of it to messageBox without knowing which row or column to choose. i wrote this code:
Private Sub Command1_Click()
On Error GoTo Err
StartExcel
Set ExcelWBk = Excel.Workbooks.Open(App.Path & "\Dataku.xls")
Set ExcelWS = ExcelWBk.Worksheets(1)
With ExcelWS
Dim i As Integer
Dim strData As String
For i = 1 To 5
strData = strData & .Cells(i, 1) & vbCrLf
Next i
End With
MsgBox strData
CloseWorkSheet
ClearExcelMemory
Exit Sub
Err:
ClearExcelMemory
End Sub
but it returned into datas of that column (column 1) only. i need to read whole excel file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的东西(在PowerPoint中测试,因为我没有VB6)将逐个单元格地获取第一个工作表的
UsedRange
(使用数组以提高效率)请更改您的文件路径以适应。
第一个版本 - 在 PowerPoint 中测试
VBS 版本
Something like this (tested in PowerPoint as I dont have VB6) will get the
UsedRange
of the first sheet cell by cell (using an array for efficiency)Pls change your file path to suit.
First version - tested in PowerPoint
VBS version