我试图将来自不同文件夹的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”,如果可能的话,能否使用通配符来指定子文件夹?