Try this...
Public Sub Listbox2Textfile(Listbox1 As Listbox, Filename As String)
Dim f As Integer
Dim h As Long
f=Freefile
Open Filename For Output As #f
For h = 0 To Listbox1.ListCount-1
Print #f, Listbox1.List(h)
Next h
Close #f
End Sub
Make the file extension ".txt" for a text file, or ".csv" for Excel.
> I Have a small app that adds it's results to a list box, what I want to do
> is save the contents of this box to a text file or better still an excel
[quoted text clipped - 3 lines]
>
> Dave L
Dave Lewis - 31 Oct 2004 17:30 GMT
Can you give an example? I keep getting 'expected =' or 'syntax error' when
trying this
Private Sub Command2_Click()
printfile = "c:\test.csv"
Listbox2Textfile (List1,printfile)
End Sub
or have I got the wrong end of the stick here?
Regards
DL
> Try this...
>
[quoted text clipped - 18 lines]
> >
> > Dave L
Rick Rothstein - 31 Oct 2004 17:37 GMT
> Can you give an example? I keep getting 'expected =' or 'syntax error' when
> trying this
>
> Private Sub Command2_Click()
> printfile = "c:\test.csv"
> Listbox2Textfile (List1,printfile)
You have the syntax wrong; remove the parentheses from around the
argument list to the Sub. Parentheses are only used with a Sub if the
Call keyword is used. The above line should be either this...
Listbox2Textfile List1, printfile
or this...
Call Listbox2Textfile(List1, printfile)
Rick - MVP
Dave Lewis - 31 Oct 2004 21:11 GMT
That did it thank you both