You could store them as a customer property.
Each listbox name would be use to store a string of CSV for later use.
Each CSV would represent the selected value in the listbox.
If you had a list of ten in Listbox1 and 1,3 7 items are selected, this would generate a CSV like:
Listbox1,1,3,7
which you can parse later with the Split function.
Private Sub cmdSave_Click()
Dim Ctrl As Control
Dim A As Long
Dim LBAry As String
For Each Ctrl In Me.Controls
Select Case Ctrl.Name
Case "ListBox"
LBAry = Ctrl.Name & ","
For A = 0 To Ctrl.ListCount - 1
If Me.Ctrl.Selected(A) Then
LBAry = LBAry & A & ","
End If
Next
'Strip off trailing comma.
LBAry = Left(LBAry, Len(LBAry) - 1)
StoreVariable Ctrl.Name, LBAry
End Select
Next
End Sub
Sub StoreVariable(Varname As String, VarValue As String)
'http://www.vbaexpress.com/kb/getarticle.php?kb_id=677
' ============================================
' Save a value in CustomDocumentProperties
' ============================================
' If the name doesn't exist, we create it and set the initial value to 1
On Error Resume Next
Dim cstmDocProp As DocumentProperty
Set cstmDocProp = ThisWorkbook.CustomDocumentProperties(Varname)
If Err.Number > 0 Then
ThisWorkbook.CustomDocumentProperties.Add _
Name:=Varname, _
LinkToContent:=False, _
Type:=msoPropertyTypeNumber, _
Value:=VarValue
' ========================================================================
Else
' ========================================================================
' if our name exists, we need to store the csv.
ThisWorkbook.CustomDocumentProperties(Varname).Value = VarValue
' ========================================================================
End If
' Explicitly clear memory
Set cstmDocProp = Nothing
End Sub
Bookmarks