【发布时间】:2022-07-17 10:22:56
【问题描述】:
我正在尝试将不同文件夹中的 Excel 文件合并到一个文件夹中。每个文件夹中都有一个 Excel 文件。
Sub move_data()
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim Fdate As Date
Dim FileInFromFolder As Object
MkDir "C:\User\TEST\"
FromPath = "C:\User\MainFolder\"
ToPath = "C:\User\TEST\"
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub
End If
For Each FileInFromFolder In FSO.GetFolder(FromPath).Files
FileInFromFolder.Move ToPath
Next FileInFromFolder
End Sub
代码无法从文件夹内的子文件夹中获取文件(如图所示)。
我希望更改的区域是“FromPath”,是否可以包含通配符来指定子文件夹?
【问题讨论】:
-
This 将帮助您循环浏览文件夹和子文件夹。只需调整它以仅移动 Excel 文件