Export list box records to excel (1 Viewer)

JPR

Registered User.
Local time
Today, 06:17
Joined
Jan 23, 2009
Messages
192
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:17
Joined
May 7, 2009
Messages
19,237
...
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:

JPR

Registered User.
Local time
Today, 06:17
Joined
Jan 23, 2009
Messages
192
That's just perfect! Great help. Thanks Arnel
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:17
Joined
May 7, 2009
Messages
19,237
you're welcome.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:17
Joined
Oct 29, 2018
Messages
21,468
Hi. Just curious, could you have used the CopyFromRecordset method as well?

Sent from phone...
 

Users who are viewing this thread

Top Bottom