Hi,
Confused to why i am getting this error
I'm just trying to loop over all excel files and copy them but i get an error in the highlighted part in bold
Thank You
Confused to why i am getting this error
I'm just trying to loop over all excel files and copy them but i get an error in the highlighted part in bold
Thank You
Code:
Dim fso As Scripting.filesystemobject
Dim NewFolderPath As String
Sub CreateFolder()
Dim fso As Scripting.filesystemobject
Set fso = New Scripting.filesystemobject
Dim OldFolderPath As String
NewFolderPath = "C:\Users\Helal\Desktop\Excel Test\New Folder"
OldFolderPath = "C:\Users\Helal\Desktop\Excel Test\Old Folder"
If fso.FolderExists(NewFolderPath) Then
MsgBox "It exists"
Else
fso.CreateFolder (NewFolderPath)
End If
Call CopyExcelFiles(OldFolderPath)
End Sub
Sub CopyExcelFiles(StartFolderPath As String)
Dim fil As Scripting.File
Dim OldFolder As Scripting.Folder
Dim SubFol As Scripting.Folder
[U][B]Set OldFolder = fso.GetFolder(StartFolderPath)[/B][/U]
For Each fil In OldFolder.Files
If Left(fso.GetExtensionName(fil.Path), 2) = "xl" Then
If fso.FileExists(NewFolderPath & "\" & fil.Name) Then
MsgBox "File Already Exists"
Else
fil.Copy NewFolderPath & "\" & fil.Name
End If
End If
Next
For Each SubFol In OldFolder.SubFolders
Call CopyExcelFiles(SubFol.Path)
Next
End Sub