A
and
I would like to use a procedure again and again for several listboxes in
a user form.
Therefore, I need to use a variable that can represent the various list
boxes.
Which variable type should I use?
=========================
Private Sub userform_initiate()
Dim oLBox As Object 'Object type DOES NOT WORK
End Sub
-------------------------
Private Sub butBrowse01_click() 'Browse button 01 next to list box 01
oLBox = ThisUserForm.ListBox_01
SelectFiles (False) 'AllowMultiSelect = false
End Sub
-------------------------
Private Sub SelectFiles(bMultSel As Boolean)
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Dim vrtSelectedItem As Variant
With fd
.AllowMultiSelect = bMultSel
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
oLBox.AddItem (vrtSelectedItem) '???
Next
Else
End If
End With
Set fd = Nothing
End Sub
=========================
ANDy
a user form.
Therefore, I need to use a variable that can represent the various list
boxes.
Which variable type should I use?
=========================
Private Sub userform_initiate()
Dim oLBox As Object 'Object type DOES NOT WORK
End Sub
-------------------------
Private Sub butBrowse01_click() 'Browse button 01 next to list box 01
oLBox = ThisUserForm.ListBox_01
SelectFiles (False) 'AllowMultiSelect = false
End Sub
-------------------------
Private Sub SelectFiles(bMultSel As Boolean)
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Dim vrtSelectedItem As Variant
With fd
.AllowMultiSelect = bMultSel
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
oLBox.AddItem (vrtSelectedItem) '???
Next
Else
End If
End With
Set fd = Nothing
End Sub
=========================
ANDy