silentwolf
Well-known Member
- Joined
- May 14, 2008
- Messages
- 1,216
- Office Version
- 2016
Hi guys,
I have worked through some tutorials from WiseOwl regarding FilesAndFolders where "Andrew Gould"
It is a great video!
However if I run the recursive Function looping through all the Folders containing Say Excel Files .. within a Main Directory then after a while I get a runtime Error 70 Access denied.
My Code is not in any file where the OldFoldePath or the NewFolderPath.
So this Code above is located in some other directory so not in the "OldFolderPath" nor in the "NewFolderPath"
Can someone let me know what the issue could be?
Cheers
Albert
I have worked through some tutorials from WiseOwl regarding FilesAndFolders where "Andrew Gould"
It is a great video!
However if I run the recursive Function looping through all the Folders containing Say Excel Files .. within a Main Directory then after a while I get a runtime Error 70 Access denied.
My Code is not in any file where the OldFoldePath or the NewFolderPath.
VBA Code:
'From Andrew Gould WiseOwl'
Dim fso As Scripting.FileSystemObject
Dim NewFolderPath As String
Sub UsingTheScriptingRuntimeLibrary()
Dim OldFolderPath As String
NewFolderPath = Environ("UserProfile") & "\Desktop\NeuerOrdner"
OldFolderPath = "Y:\BUSINESS\PROGRAMMING"
Set fso = New Scripting.FileSystemObject
If fso.FolderExists(OldFolderPath) Then
If Not fso.FolderExists(NewFolderPath) Then
fso.CreateFolder NewFolderPath
End If
Call CopyExcelFiles(OldFolderPath)
End If
Set fso = Nothing
End Sub
Sub CopyExcelFiles(StartFolderPath As String)
Dim fil As Scripting.File
Dim subfol As Scripting.Folder
Dim OldFolder As Scripting.Folder
Set OldFolder = fso.GetFolder(StartFolderPath)
For Each fil In OldFolder.Files
If Left(fso.GetExtensionName(fil.Path), 4) = "xlsx" Then
fil.Copy NewFolderPath & "\" & fil.Name
End If
Next fil
For Each subfol In OldFolder.SubFolders
Call CopyExcelFiles(subfol.Path)
Next subfol
End Sub
So this Code above is located in some other directory so not in the "OldFolderPath" nor in the "NewFolderPath"
Can someone let me know what the issue could be?
Cheers
Albert