JonRowland
Active Member
- Joined
- May 9, 2003
- Messages
- 417
- Office Version
- 365
- Platform
- Windows
Hi guys,
I'm pulling my hair out as to why the following isn't working. Basically, I am looking to move CSV files from one folder to a another one which will be create if doesn't exist.
However, when the below is run FSO.CreateFolder (ToPath) gives me an Error 76 - PATH NOT FOUND, rather than create within H:\StartFolder the new subfolders and subfolder within "\MoveItHere\BaseFiles".
What am I missing?
<code>
Sub Move_Certain_Files_To_New_Folder()
' This example move all Excel files from FromPath to ToPath.
' Note: It will create the folder ToPath
' Sourced from https://www.rondebruin.nl/win/s3/win026.htm
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
Dim FNames As String
Dim strFromDir As String
Dim strSavedFilePath As String
strFromDir = "H:\StartFolder"
strSavedFilePath = strFromDir + "" + "MoveItHere\BaseFiles"
Err = 0 ' For debugging
' Set Paths. Variables used as will be set Public prior to reaching this code.
FromPath = strFromDir
ToPath = strSavedFilePath
FileExt = "*.csv" '
If Right(FromPath, 1) <> "" Then
FromPath = FromPath & ""
End If
FNames = Dir(FromPath & FileExt)
If Len(FNames) = 0 Then
MsgBox "No files in " & FromPath
Exit Sub
End If
On Error Resume Next
Set FSO = CreateObject("scripting.filesystemobject")
' Create New Folder
FSO.CreateFolder (ToPath) ' Error 76 PATH NOT FOUND
FSO.MoveFile Source:=FromPath & FileExt, Destination:=ToPath
End Sub
</code>
I'm pulling my hair out as to why the following isn't working. Basically, I am looking to move CSV files from one folder to a another one which will be create if doesn't exist.
However, when the below is run FSO.CreateFolder (ToPath) gives me an Error 76 - PATH NOT FOUND, rather than create within H:\StartFolder the new subfolders and subfolder within "\MoveItHere\BaseFiles".
What am I missing?
<code>
Sub Move_Certain_Files_To_New_Folder()
' This example move all Excel files from FromPath to ToPath.
' Note: It will create the folder ToPath
' Sourced from https://www.rondebruin.nl/win/s3/win026.htm
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
Dim FNames As String
Dim strFromDir As String
Dim strSavedFilePath As String
strFromDir = "H:\StartFolder"
strSavedFilePath = strFromDir + "" + "MoveItHere\BaseFiles"
Err = 0 ' For debugging
' Set Paths. Variables used as will be set Public prior to reaching this code.
FromPath = strFromDir
ToPath = strSavedFilePath
FileExt = "*.csv" '
If Right(FromPath, 1) <> "" Then
FromPath = FromPath & ""
End If
FNames = Dir(FromPath & FileExt)
If Len(FNames) = 0 Then
MsgBox "No files in " & FromPath
Exit Sub
End If
On Error Resume Next
Set FSO = CreateObject("scripting.filesystemobject")
' Create New Folder
FSO.CreateFolder (ToPath) ' Error 76 PATH NOT FOUND
FSO.MoveFile Source:=FromPath & FileExt, Destination:=ToPath
End Sub
</code>