Export list box records to excel

JPR

Registered User.
Local time
Today, 12:35
Joined
Jan 23, 2009
Messages
202
Hello friends,

Searching several web sites, I have found a great code to export contents of a listbox directly to Excel.
The only problem is that it does not export the "0" column.
My listbox has 11 columns and the code exports data starting the count from column 1. Is there a way anyone can help me with this? Thank you

Dim appExcel As Excel.Application
Dim wksData As Excel.Worksheet
Dim intColumn_Index As Integer
Dim intRow_Index As Integer

Set appExcel = New Excel.Application
appExcel.Workbooks.Add
Set wksData = appExcel.Workbooks(1).Worksheets(1)
For intRow_Index = 1 To lstStudy.ListCount ' lstStudy is the name of my list box
For intColumn_Index = 1 To lstStudy.ColumnCount
wksData.Cells(intRow_Index + 1, intColumn_Index).Value = lstStudy.Column(intColumn_Index, intRow_Index) ' this is the line I get the error
Next intColumn_Index
Next intRow_Index
appExcel.Visible = True
Set wksData = Nothing
Set appExcel = Nothing
End Sub
 
...
For intRow_Index = 0 To lstStudy.ListCount - 1
For intColumn_Index = 0 To lstStudy.ColumnCount - 1
wksData.Cells(intRow_Index + 1, intColumn_Index + 1).Value = lstStudy.Column(intColumn_Index, intRow_Index)
 
Last edited:
That's just perfect! Great help. Thanks Arnel
 
you're welcome.
 
Hi. Just curious, could you have used the CopyFromRecordset method as well?

Sent from phone...
 

Users who are viewing this thread

Back
Top Bottom