How to Save Listbox to File. This tutorial shows you how to save the contents of a listbox. Make sure you have a CommonDialog control added to your form. Put something like this in a button:
On Error GoTo handleError
Dim fileName As String, msgResult As VbMsgBoxResult, i As Long
CommonDialog1.CancelError = True
CommonDialog1.Filter = "Text Files (*.txt)|*.txt"
CommonDialog1.FilterIndex = 0
CommonDialog1.ShowSave
fileName = CommonDialog1.fileName
If Len(Dir(fileName)) <> 0 Then
msgResult = MsgBox("This file already exists: """ + fileName + """, do you wish replace it?", vbYesNo, "Error")
If msgResult = vbNo Then Exit Sub
End If
Open fileName For Output As #1
For i = 0 To List1.ListCount - 1
Print #1, List1.List(i) + Chr(13)
Next
Close #1
handleError: Exit Sub
0 comments:
Posting Komentar