vb 请问如何将listbox的内容转写到excel

2024-12-03 04:23:25
推荐回答(1个)
回答1:

先引用 Microsoft Excel x.0 object library
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Set xlBook = xlApp.Workbooks.Open("路径.XLS") '打开要保存的excel
Set xlsheet = xlBook.Worksheets(1)
For i = 0 To list1.ListCount - 1 'list1里面的内容
xlsheet.Cells(i + 1, 1) = list1.List(i) '转到excel
Next i
xlBook.Close SaveChanges:=True '以下三行关闭excel
xlApp.Quit
Set xlApp = Nothing
O(∩_∩)O~