I'm using FileSystemObject to loop from files in folder, but I found that in some cases I'm missing files.
I have a folder with 20 files and when trying to list them I only see 14. The path is very long, so it seems to skip the files with >250 characters long.
Sub CountFilesInFolder()
Dim xFileSystemObject As Object
Dim xFolder As Object
Dim xFile As Object
Dim countx As Long
Dim xFolderName As String
Dim rowIndex As Long
xFolderName = "\\server\[long folder name]"
Set xFileSystemObject = CreateObject("Scripting.FileSystemObject")
Set xFolder = xFileSystemObject.GetFolder(xFolderName)
For Each xFile In xFolder.Files
rowIndex = rowIndex + 1
Application.ActiveSheet.Cells(rowIndex, 1).Formula = xFile.Name
Next
End Sub
Is there any other way to extract the list of files (and information from the files) using vba?
I tried both methods from another question here, but I got the same problem