Is it possible to recall the value selected (highlighted blue) in a userform listbox when form is shown again.
Below code uses arrays to show subfolders in a listbox.
Below code uses arrays to show subfolders in a listbox.
VBA Code:
Option Explicit
Private Sub UserForm_Initialize()
Dim file_system As Object, sub_folder As Object
Dim main_folder As String
Dim arr_path As Variant
Dim m As Long
Set file_system = CreateObject("Scripting.FileSystemObject")
main_folder = "C:\My Documents\" 'Change as required
'Array Folderpaths
m = 0
ReDim arr_path(0)
If file_system.FolderExists(main_folder) Then
For Each sub_folder In file_system.GetFolder(main_folder).SubFolders
arr_path(m) = file_system.GetAbsolutePathName(sub_folder)
m = m + 1
ReDim Preserve arr_path(m)
Next sub_folder
End If
'Populate listbox
For m = 0 To UBound(arr_path)
ListBox1.AddItem arr_path(m)
Next m
End Sub