Mr_Ragweed2
Board Regular
- Joined
- Nov 11, 2022
- Messages
- 145
- Office Version
- 365
- Platform
- Windows
I'm guessing i just need a fresh set of eyes to look at this. I have some pdf files on my c:drive that i am wanting to move to sharepoint. I have other code in which i save directly to sharepoint and it works fine. I ran a test to see if i can save to another folder in my C:drive and it works as well. When i run a messagebox the pathway addresses look to be correct but i get the "bad path or filename error" when i try and execute the code. (I marked the line where the error occurs). My File.Name and sourceFilePath are correct and like i said the destFilePath looks to be correct. What am i missing here?
if this looks familiar you are correct. i had an earlier thread with a different error on the same code. Since i have a new question/error i thought i should start a new thread. Here is the link to my other thread if that is relevant.
"invalid procedure call or argument"
Thanks for any help you can provide. I do mark solutions when i get them and i click the thumbs up even though i'm not sure what that actually does lol.
VBA Code:
Option Explicit
Private Sub CommandButton1_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 newpath As String 'debugging pathway test
Dim FSO As Object
Dim SourceFolder As Object
Dim File As Object
Application.ScreenUpdating = False
Dim MyName As String
MyName = Environ$("Username")
sourceFolderPath = "C:\Users\" & MyName & "\OneDrive - my company Inc\Desktop\Propane Forms"
'newpath = "C:\Users\" & MyName & "\OneDrive - my company Inc\Desktop\Path Test Folder" ' debugging pathway test
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)
For Each File In SourceFolder.Files
fileName = File.Name
If fileName Like "*SWO*.PDF" Then
sourceFilePath = File.Path
destFilePath = SWOPath & File.Name
'destFilePath = newpath & "/" & File.Name ' debugging pathway test
FSO.MoveFile Source:=sourceFilePath, Destination:=destFilePath ' error is on this line
'MsgBox "W: " & File.Name & ", " & sourceFilePath & ", " & destFilePath
ElseIf fileName Like "*TMS*.PDF" Then
sourceFilePath = File.Path
destFilePath = TMSPath & "/" & File.Name
FSO.MoveFile Source:=sourceFilePath, Destination:=destFilePath
'MsgBox "T: " & File.Name & ", " & sourceFilePath & ", " & destFilePath
End If
Next
Set SourceFolder = Nothing
Set FSO = Nothing
End Sub
if this looks familiar you are correct. i had an earlier thread with a different error on the same code. Since i have a new question/error i thought i should start a new thread. Here is the link to my other thread if that is relevant.
"invalid procedure call or argument"
Thanks for any help you can provide. I do mark solutions when i get them and i click the thumbs up even though i'm not sure what that actually does lol.