Hi antoka05,
Thanks for taking the time to go over the code and providing your feedback. It is higly appreciated. This approach is new to me, but I'm new to vba 
So you have replaced the original code for looping through files by using the Dir function:
Option Explicit
Sub GetTxtFiles_old()
Dim sFName As String
Dim fPath As String
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Show
If .SelectedItems.Count > 0 Then fPath = .SelectedItems(1) & "\"
End With
sFName = Dir$(fPath & "*.txt")
Do While Len(sFName)
' Do something
sFName = Dir$()
Loop
End Sub
to this new code (which by the way works so far when the first code did not):
Option Explicit
Sub GetTxtFiles()
Dim fso As Object
Dim fPath As String
Dim myFolder, myFile
Set fso = CreateObject("Scripting.FileSystemObject")
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Show
If .SelectedItems.Count > 0 Then fPath = .SelectedItems(1) & "\"
End With
Set myFolder = fso.GetFolder(fPath).Files
For Each myFile In myFolder
If LCase(myFile) Like "*.txt" Then
' Do something
End If
Next myFile
End Sub
So far, this has circumvented the issues caused by Dir and I will definately test it for speed and accurracy on multiple operating systems.
In general do you always use this method or only when Dir fails?
Thanks again.
abousetta
Bookmarks