radonwilson
New Member
- Joined
- Jun 23, 2021
- Messages
- 41
- Office Version
- 2019
- Platform
- Windows
My code is opening files in alphabetical order. I want to open them in numerical order.
I have 11 files in my folder with serial number and their names.
Code is opening file in this way : 1→10→11→2→3→4→5→6→7→8→9
I have 11 files in my folder with serial number and their names.
Code is opening file in this way : 1→10→11→2→3→4→5→6→7→8→9
VBA Code:
Option Explicit
Sub check()
Dim FPath As String 'file's folder path
Dim FName As String 'file's name
Dim wbT As Workbook
Dim wbS As Workbook
Set wbT = ThisWorkbook
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select your Folder"
.ButtonName = "Select Folder"
If .Show = 0 Then
MsgBox ("Nothing was Selected")
Else
FPath = .SelectedItems(1) & "\"
End If
End With
FName = VBA.FileSystem.Dir(FPath & "*.csv*")
Do Until FName = ""
If wbT.Sheets(1).Range("A1").Value = "" Then
Set wbS = Application.Workbooks.Open(FPath & FName)
wbS.Sheets(1).Range("a1").CurrentRegion.Select
Else
End If
FName = Dir
Loop
End Sub