"invalid procedure call or argument"

Mr_Ragweed2

Board Regular
Joined
Nov 11, 2022
Messages
145
Office Version
  1. 365
Platform
  1. 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.


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:
So i think it has to be the path to sharepoint..
It's possible. I don't know if it is possible and what the nomenclature should be in sharepoint files.
You should look for more examples on this page or on the web.
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Yes, i am doing so now. I think it has to be sharepoint since my "test path folder" destination on the c drive worked - so obviously not a sourcepath issue. it found the right files and moved them correctly in that scenario.
THANK YOU so much for your help on this!!!! I want to mark one of your posts as a solution...though not entirely solved -you did point me in the right direction. If i find the rest of the solution i will post it here for others.
 
Upvote 0
I want to mark one of your posts as a solution
Of course, you can mark the one you like, since your macro had other details to resolve. 😇



check this:

 
Upvote 0
I think i found the problem. I uploaded a test pdf to sharepoint (Teams) to double check the pathway. The file name is in the following format "WSO John Smith 14-Dec-2023 8-54 AM" with space between everything. However when i copy the link everything has the "%20" where the spaces would be. I don't want to concatenate the %20 into each file name because then it will look like trash. Do you know how to concatenate just to a pathway? Is that even possible? I guess i could hyphenate all of the file names as a work around....
Probably a new thread??
 
Upvote 0

Forum statistics

Threads
1,224,884
Messages
6,181,556
Members
453,053
Latest member
Kiranm13

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top