VB读取excel几个单元格的数据?

来源:百度知道 编辑:UC知道 时间:2024/05/26 17:15:02
比如要读取book1.xls中P2到P6,5个单元格的数据。怎么实现啊?
要让读取的数据显示在text上,并且用逗号隔开。

Dim ExcelApp
set ExcelApp = CreateObject("Excel.Application")
dim oBook
Set oBook = ExcelApp.WorkBooks.Open("d:\book1.xls")
dim strText As String
strText = ""
For i = 2 to 6
strText = strText & oBook.WorkSheets("Sheet1").Range("P"&cstr(i)).Value & ","
Next
Text1.Text = Mid(strText,1,Len(StrText)-1)