Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-16-2022, 12:50 AM
Bikram Bikram is offline Looping in Correct order Windows 10 Looping in Correct order Office 2007
Advanced Beginner
Looping in Correct order
 
Join Date: Jul 2021
Location: Nepal
Posts: 90
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Combobox Looping blaisjoel Word VBA 1 04-17-2019 05:50 AM
How do I paste items in the order they were copied, not the order the are listed? manish500 Word 6 07-25-2018 12:07 AM
Looping several slides gabby PowerPoint 11 04-25-2015 03:05 AM
Looping in Correct order Need help on macro for looping kilosub Word VBA 31 07-27-2011 01:37 PM
Looping video tomasball PowerPoint 0 10-30-2010 02:38 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:10 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft