Nader
02-13-2008, 07:11 AM
I tried this code to save the text of the listbox called "lstM" ( I placed on sheet1) in the sheet3 and after open the book it shows the text in the the listbox. it successd with me.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Sheets(3).Range("a:a").Value = ""
For i = 0 To Sheets("sheet1").lstM.ListCount - 1
Sheets("sheet3").Cells(i + 2, 1).Value = Sheets("sheet1").lstM.List(i)
Next
Sheets("sheet3").Cells(1, 1).Value = Sheets("sheet1").lstM.ListCount
End Sub
Private Sub Workbook_Open()
For i = 0 To Sheets("sheet3").Cells(1, 1).Value
Sheets("sheet1").lstM.AddItem Sheets("sheet3").Cells(i + 2, 1).Value
Next
End Sub
I placed a listbox called "lstM" on the UserForm and tried this code to save the text in sheet 3 to show the text of the the listbox . It saved the text but with balnk rows
How can I fix this problem
Private Sub UserForm_Activate()
For i = 0 To Sheets("sheet3").Cells(1, 1).Value
UserForm1.lstM.AddItem Sheets("sheet3").Cells(i + 2, 1).Value
Next i
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Sheets(3).Range("a:a").Value = ""
For i = 0 To lstM.ListCount - 1
Sheets("sheet3").Cells(i + 2, 1).Value = lstM.List(i)
Next i
Sheets("sheet3").Cells(1, 1).Value =UserForm1. lstM.ListCount
End Sub
Take a look to the excel file
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Sheets(3).Range("a:a").Value = ""
For i = 0 To Sheets("sheet1").lstM.ListCount - 1
Sheets("sheet3").Cells(i + 2, 1).Value = Sheets("sheet1").lstM.List(i)
Next
Sheets("sheet3").Cells(1, 1).Value = Sheets("sheet1").lstM.ListCount
End Sub
Private Sub Workbook_Open()
For i = 0 To Sheets("sheet3").Cells(1, 1).Value
Sheets("sheet1").lstM.AddItem Sheets("sheet3").Cells(i + 2, 1).Value
Next
End Sub
I placed a listbox called "lstM" on the UserForm and tried this code to save the text in sheet 3 to show the text of the the listbox . It saved the text but with balnk rows
How can I fix this problem
Private Sub UserForm_Activate()
For i = 0 To Sheets("sheet3").Cells(1, 1).Value
UserForm1.lstM.AddItem Sheets("sheet3").Cells(i + 2, 1).Value
Next i
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Sheets(3).Range("a:a").Value = ""
For i = 0 To lstM.ListCount - 1
Sheets("sheet3").Cells(i + 2, 1).Value = lstM.List(i)
Next i
Sheets("sheet3").Cells(1, 1).Value =UserForm1. lstM.ListCount
End Sub
Take a look to the excel file