Greeting to all, Below is my code for looping through files in a folder but where I face the problem is it jumps from 01 to 10, 11, 12, and so on. What should be done on following code so that it loops sequentially?
Code:
Sub loopfo()
Dim fso As FileSystemObject
Dim fld As FileDialog,strname As String,fp As String,fdr As Scripting.folder,f As Scripting.file
Dim doc As Document
On Error Resume Next
Set fld = Application.FileDialog(msoFileDialogFolderPicker)
With fld
.Show
.AllowMultiSelect = False
.Title = "Select the Desired Folder"
End With
fp = fld.SelectedItems(1)
Set fso = New Scripting.FileSystemObject
Set fdr = fso.GetFolder(fp)
For Each f In fdr.Files
If Left(fso.GetExtensionName(f.Path), 3) = "doc" Then ' And Left(f.Name, 2) = "0"
Set doc = Documents.Open(f.Path)
doc.Close (True)
End If
Next
End Sub
Any suggestions would be appreciated. Thanks in advance.