PDA

View Full Version : How to save the item in the listbox



Nader
01-19-2008, 02:20 AM
I use this code to add item into listbox and remove item into listbox


ListBox2.AddItem TextBox1.Text
ListBox2.ListIndex = ListBox2.ListCount - 1

ListBox2.RemoveItem ListBox2.ListIndex
ListBox2.ListIndex = ListBox2.ListCount - 1

But after I add the item the workbook doesn't save the item . How can I save the item in the list box?

Bob Phillips
01-19-2008, 02:45 AM
You would need to save the listbox items on the form exit somwehere, probably in a worksheet, and then restore it next time you restart the form.

If it is just for this session, don't unload the form, hide it.

Nader
01-19-2008, 03:57 AM
I don't have form the listbox is palced on the sheet1

Bob Phillips
01-19-2008, 04:22 AM
Same principle.

Nader
01-19-2008, 06:06 AM
I tried , but didn't success


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Litbox2.Text
End Sub

lucas
01-19-2008, 07:31 AM
Do yo want the same info to be in the listbox when you open the workbook the next time? if so see Bob's(XLD) post #2. It says that when you close the workbook to put the value in a cell somewhere and then on workbook open to repopulate your listbox from the cell..if I understand correctly.

Nader
01-19-2008, 03:55 PM
I'm beginner. may you help I don't know how to do that.