Home > Article > Computer Tutorials > How to use VBA programming to specify a folder path and open files matching a specific suffix in order
Sub Test()
Dim myPath As String, MyName As String
myPath = "C:\Documents\" 'Get Path
MyName = Dir(myPath) 'find the first file
If Right(MyName, 4) = ".csv" Then Workbooks.Open Filename:=myPath & MyName
Do While MyName """
MyName = Dir 'find next
If Right(MyName, 4) = ".csv" Then Workbooks.Open Filename:=myPath & MyName
Loop
End Sub
Sub DateSave()
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
ThisWorkbook.Path & "\"" & Date & ".xls", _
FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, _
CreateBackup:=False
Application.DisplayAlerts = True
End Sub
Please change "ThisWorkbook.Path & "\"" & Date & ".xls", _" to ""d:\" & Date & ".xls", _", where ""d:\" " This is the path you want to save.
Hopefully my answer is of help to you.
The above is the detailed content of How to use VBA programming to specify a folder path and open files matching a specific suffix in order. For more information, please follow other related articles on the PHP Chinese website!