Userform med listboxe
Flg. kode bruges i intialize til at fylde listbox2 med de mapper, som er i "Min fil".Det jeg har forestillet mig er, at ved at trykke på et af undermappenavnene i listbox2, skal dokumentfilerne i pågældende valgte mappe listes op i listbox1
Private Sub UserForm_Initialize()
Dim objFSO As Object
Dim ObjFolder As Object
Dim objSubFolder As Object
'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
Set ObjFolder = objFSO.GetFolder("C:\Min fil")
'loops through each file in the directory and prints their names and path
For Each objSubFolder In ObjFolder.subfolders
Me.ListBox1.AddItem objSubFolder.Name
Next objSubFolder
End Sub
Flg. kode kan evt bruges til at "liste" dokumentfilerne i valgte mappe op i listbox1:
Private Sub CommandButton2_Click()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
Set objFolder = objFSO.GetFolder("C:\Min fil + valgt mappe fra listbox2")
'loops through each file in the directory and prints their names and path
For Each objFile In objFolder.Files
Me.ListBox1.AddItem objFile.Path
Next objFile
End Sub