View Single Post
 
Old 03-16-2022, 12:50 AM
Bikram Bikram is offline Windows 10 Office 2007
Advanced Beginner
 
Join Date: Jul 2021
Location: Nepal
Posts: 94
Bikram is on a distinguished road
Post Looping in Correct order

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.
Reply With Quote