VB6.0读取EXCEL工作表中区域内的数据

2024-11-07 18:08:43
推荐回答(1个)
回答(1):

Private Sub Command1_Click()
Dim Xlbook As Workbook
Dim Xlapp As Application
Dim Xlsheet As Worksheet
Set Xlapp = CreateObject("Excel.Application") '隐藏方式打开excel
Set Xlbook = Xlapp.Workbooks.Open("D:\123.xls") '打开工作簿
Set Xlsheet = Xlbook.Worksheets(1) '让xlsheet代表第一个表

Print Xlsheet.Range("A1") '取数据什么的跟VBA一样的。

Xlbook.Close False '关闭工作簿 不保存
Set Xlapp = Nothing '释放
Set Xlbook = Nothing
End Sub