Hi Guys,
I have a bunch of excel workbooks with names like these :
BOCOM_HK_719286_06260329_P1
BOCOM_HK_719286_06260329_P2
BOCOM_HK_719286_06260329_P3
...
BOCOM_HK_719286_06260329_P11
I need to open these files in the ascending numeric order (p1,p2,p3,p4 etc.)
however, currently the opening order is:
BOCOM_HK_719286_06260329_P1
BOCOM_HK_719286_06260329_P10
BOCOM_HK_719286_06260329_P2
BOCOM_HK_719286_06260329_P20
BOCOM_HK_719286_06260329_P3
BOCOM_HK_719286_06260329_P4
...
The code seems to priortize p10 over p2 and p20 over p3 etc.
What changes should I make to acheived the desired results?
Thanks.
The related section of my code is as follows:
I have a bunch of excel workbooks with names like these :
BOCOM_HK_719286_06260329_P1
BOCOM_HK_719286_06260329_P2
BOCOM_HK_719286_06260329_P3
...
BOCOM_HK_719286_06260329_P11
I need to open these files in the ascending numeric order (p1,p2,p3,p4 etc.)
however, currently the opening order is:
BOCOM_HK_719286_06260329_P1
BOCOM_HK_719286_06260329_P10
BOCOM_HK_719286_06260329_P2
BOCOM_HK_719286_06260329_P20
BOCOM_HK_719286_06260329_P3
BOCOM_HK_719286_06260329_P4
...
The code seems to priortize p10 over p2 and p20 over p3 etc.
What changes should I make to acheived the desired results?
Thanks.
The related section of my code is as follows:
Code:
Sub BOCOM()
Dim MyFolder As String
Dim MyFile As String
Dim wb As Workbook
MyFolder = "C:\Users\" & user & "\Desktop\New folder"
MyFile = Dir(MyFolder & "\*.csv")
Do While MyFile <> ""
Set wb = Workbooks.Open(filename:=MyFolder & "\" & MyFile)
wb.Close savechanges:=False
MyFile = Dir
Loop