Mr_Ragweed2
Board Regular
- Joined
- Nov 11, 2022
- Messages
- 145
- Office Version
- 365
- Platform
- Windows
Hello and thanks. I am using some code from the web that supposedly works according to the user. (His question was to adapt it to different types files, not functionality). For my purposes i have tried to adapt it as a loop for multiple destinations. As you will see below i have added 2 destination paths. I have changed nothing else in the code. I am getting an error for invalid procedure call or argument" on the " Set SourceFolder = " line. I have reread the original code to see if i left something out and i cannot find any differences. Any help is greatly appreciated.
Update: When i step through it gives "Path Not found" on the same line i mentioned earlier.
VBA Code:
Private Sub CommandButton_Click()
Dim sourceFilePath As String
Dim destFilePath As String
Dim sourceFolderPath As String
Dim fileName As String
Dim SWOPath As String 'destination folder path 1
Dim TMSPath As String 'destination folder path 2
Dim FSO As Object
Dim SourceFolder As Object
Dim File As Object
Application.ScreenUpdating = False
sourceFolderPath = "C:\Propane Forms"
SWOPath = "https://abcd.sharepoint.com/teams/mycompany/Shared%20Documents/General/Crystal,%20Mary,%20Anna/Propane%20Service%20Work%20Orders/"
TMSPath = "https://abcd.sharepoint.com/teams/mycompany/Shared%20Documents/General/Crystal,%20Mary,%20Anna/Tank%20Movement%20Sheet/"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = FSO.GetFolder(sourceFolderPath) 'error appears here when i step through the code
For Each File In SourceFolder.Files
fileName = File.Name
If InStr(fileName, "WSO", ".pdf") Then
sourceFilePath = File.Path
destFilePath = SWOPath & "\" & fileName
FSO.MoveFile Source:=sourceFilePath, Destination:=destFilePath
ElseIf InStr(fileName, "TMS", ".pdf") Then
sourceFilePath = File.Path
destFilePath = TMSPath & "\" & fileName
FSO.MoveFile Source:=sourceFilePath, Destination:=destFilePath
End If
Next
Set SorceFolder = Nothing
Set FSO = Nothing
End Sub
Update: When i step through it gives "Path Not found" on the same line i mentioned earlier.
Last edited: