VB读取Excel中单元格的内容
一个Excel文件中在一列中有好多值,我想用VB把这一列的值显示到VB窗体上的一个list控件中,要求不要打开Excel要求在后台读取。急求答案,可以将连接的代码写下来。...
一个Excel文件中在一列中有好多值,我想用VB把这一列的值显示到VB窗体上的一个list控件中,要求不要打开Excel要求在后台读取。急求答案,可以将连接的代码写下来。
展开
2个回答
展开全部
Private Sub Command1_Click()
Dim xl As Excel.Application
Dim xlbook As Excel.Workbook
Set xl = CreateObject("excel.application")
xl.Visible = False
Dim st As Excel.Worksheet
Set xlbook = xl.Workbooks.Open(App.Path & "\date.xlsx")
Set st = xlbook.Worksheets(1)
Dim i As Integer
i = 1
Do While st.Cells(i, 1).Value <> ""
List1.AddItem st.Cells(i, 1).Value
i = i + 1
Loop
Set xl = Nothing
Set xlbook = Nothing
End Sub
Dim xl As Excel.Application
Dim xlbook As Excel.Workbook
Set xl = CreateObject("excel.application")
xl.Visible = False
Dim st As Excel.Worksheet
Set xlbook = xl.Workbooks.Open(App.Path & "\date.xlsx")
Set st = xlbook.Worksheets(1)
Dim i As Integer
i = 1
Do While st.Cells(i, 1).Value <> ""
List1.AddItem st.Cells(i, 1).Value
i = i + 1
Loop
Set xl = Nothing
Set xlbook = Nothing
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询