opening excel files using the same order as in the folder

amineact

New Member
Joined
Apr 12, 2022
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Hello there
I'm trying to open all the files in a master folder while following the same order as in the workbook since each file depends on the ones before it
The problem is vba is using alphabetical order which makes some dependent files open before their source
Like i have a file "2." and "10." and "10." is dependent on "2." and it is opened and modified before "2."
I'm wondering if there is method so that i'll force vba to use the same order as in the folder.
i can't rename the files since it's company policy
I used the classic code :
VBA Code:
Dim path2 As String
path2 = "C\user\masterwork\"
MyFiles = Dir(path2 & "\*.xl*")
      Do While MyFiles <> ""
       Set wkb = Workbooks.Open(path2 & MyFiles, UpdateLinks:=3)
       Application.ScreenUpdating = False
       Application.DisplayAlerts = False
       Application.Calculation = xlAutomatic
       wkb.Close SaveChanges:=True
     MyFiles = Dir
     Loop
End sub
Thanks in advance
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
you will need another field to convert the 'text' number to numeric, then it will sort correctly (numericaly).
 
Upvote 0
Hey there thanks fo the reply
I tried your method using the sort function it still doesnt work
I should add that the files are names like 2.Input File and 10.Input file2
so is there any hope that i can make them open in the same order as the directory or none.
 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,825
Members
449,190
Latest member
rscraig11

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top