I am trying to copy files from one SharePoint folder to another.
From what I’ve read it appears that I probably need to map the SharePoint folders to network drive, but I just can’t work out how to do it.
I can’t just manually map it to my own drive as I need this to work for others, with no VBA.
Searching various sites I’ve found
Sub CopyFiles()
Dim sDocPath As String
Dim sFileName As String
Dim sTargetPath As String
Dim sSourcePath As String
Dim sDriveLetter As String
Dim fso As FileSystemObject
Dim net As WshNetwork
‘ drive letter should be available (not mapped to a share already, to avoid error ‘80070055 – The local device is already in use’)
sDriveLetter = "S:"
sFileName = "WorkBook.xlsx"
Set fso = New FileSystemObject ‘ CreateObject("Scripting.FileSystemObject")
sDocPath = ThisWorkbook.Path
‘sDocPath = ConvertPath(sDocPath)
Set net = New WshNetwork ‘ CreateObject("WScript.Network")
Debug.Print "Path to map: " & sDocPath
net.MapNetworkDrive sDriveLetter, sDocPath
sSourcePath = sDriveLetter & "Folder1" & sFileName
Debug.Print "Source: " & sSourcePath
sTargetPath = sDriveLetter "Folder2" & sFileName
Debug.Print "Target: " & sTargetPath
fso.CopyFile sSourcePath, sTargetPath, True
net.RemoveNetworkDrive sDriveLetter
Set net = Nothing
Set fso = Nothing
End Sub`
However this fell at the first hurdle as neither of these worked
Dim fso As FileSystemObject
Dim net As WshNetwork
IJustCantWorkItOut is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.