Hi,
I want to get a filelist from a specific directory (in order to import the files later on). I pulled some code of the internet and adjusted it a bit but I can't get it to work. I've pasted the code below. For some reason the part of the code inside the "With Application.FileSearch - end with" is skipped completely (if I put a msgbox within the with statements it isn't shown).
Does anyone know what I did wrong here? Any help would be much appreciated.
Kind regards,
jesse
(f_list is a dictionary object)
Sub get_filelist(src_map As String)
Dim objFSO As FileSystemObject, objFolder As Folder
Dim objFile As File, x As Long
Set objFSO = New FileSystemObject
MsgBox ("filelist functie")
f_list.RemoveAll
With Application.FileSearch
.LookIn = src_map 'look in the folder browsed to
.FileType = msoFileTypeAllFiles 'get all files
.SearchSubFolders = False
.Execute 'run the search
For x = 1 To .FoundFiles.Count 'for each file found, by the count (or index)
On Error GoTo Skip 'in the event of a permissions error
Set objFile = objFSO.GetFile(.FoundFiles(x)) 'set the object to get it's properties
f_list.Add x, objFile.Name
' Next objFile
Skip:
Next x
End With
End Sub
I want to get a filelist from a specific directory (in order to import the files later on). I pulled some code of the internet and adjusted it a bit but I can't get it to work. I've pasted the code below. For some reason the part of the code inside the "With Application.FileSearch - end with" is skipped completely (if I put a msgbox within the with statements it isn't shown).
Does anyone know what I did wrong here? Any help would be much appreciated.
Kind regards,
jesse
(f_list is a dictionary object)
Sub get_filelist(src_map As String)
Dim objFSO As FileSystemObject, objFolder As Folder
Dim objFile As File, x As Long
Set objFSO = New FileSystemObject
MsgBox ("filelist functie")
f_list.RemoveAll
With Application.FileSearch
.LookIn = src_map 'look in the folder browsed to
.FileType = msoFileTypeAllFiles 'get all files
.SearchSubFolders = False
.Execute 'run the search
For x = 1 To .FoundFiles.Count 'for each file found, by the count (or index)
On Error GoTo Skip 'in the event of a permissions error
Set objFile = objFSO.GetFile(.FoundFiles(x)) 'set the object to get it's properties
f_list.Add x, objFile.Name
' Next objFile
Skip:
Next x
End With
End Sub