Re:Save listbox into Excel
[Originally posted by Gabriel Medina]
This is an example of what you need.
Create a new project, add a Command Button (Command1) and a List Box (List1) and add the following code:
Private Sub Command1_Click()
ÿ Dim xl As Excel.Application
ÿ Dim wb As Excel.Workbook
ÿ Dim ws As Excel.Worksheet
ÿ 'Fill the list box with simple values
ÿ Me.List1.AddItem "one"
ÿ Me.List1.AddItem "two"
ÿ Me.List1.AddItem "three"
ÿ Me.List1.AddItem "four"
ÿ Me.List1.AddItem "five"
ÿ 'Automate excel
ÿ Set xl = New Excel.Application
ÿ Set wb = xl.Workbooks.Add
ÿ Set ws = wb.Worksheets.Item(1)
ÿ 'Hide the Excel window from users,
ÿ ' (unless, of course, you want them to see it).
ÿ xl.Visible = False
ÿ 'Save the values!
ÿ For n = 1 To Me.List1.ListCount
ÿ ÿ ws.Range("A" & Trim(Str(n))).Value = Me.List1.List(n - 1)
ÿ Next n
ÿ 'Save the Work Book
ÿ wb.SaveAs "Choose Your File Name.xls"
ÿ 'Clean up our mess.
ÿ Set ws = Nothing
ÿ Set wb = Nothing
ÿ Set xl = Nothing
ÿ 'Done, now you have your Excel book with the listbox data in it.
Re:Re:Save listbox into Excel
[Originally posted by soda]
Thankyou sooo much, i will give it a try, looks great to me though.