Home > Computer Tutorials > Computer Knowledge > 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
Release: 2024-01-20 09:06:19
forward
1586 people have browsed it

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!

Related labels:
source:docexcel.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template