Home  >  Article  >  Computer Tutorials  >  How to use VBA programming to specify a folder path and open files matching a specific suffix in order

How to use VBA programming to specify a folder path and open files matching a specific suffix in order

WBOY
WBOYforward
2024-01-20 09:06:191475browse

How to use VBA programming to specify a folder path and open files matching a specific suffix in order

VBA programming how to write the specified folder path and open the files that meet the suffix requirements in sequence

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

Excuse me, experts, how to select the file path and file name in which control to put in VBA

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!

Statement:
This article is reproduced at:docexcel.net. If there is any infringement, please contact admin@php.cn delete