willow1985
Well-known Member
- Joined
- Jul 24, 2019
- Messages
- 938
- Office Version
- 365
- Platform
- Windows
I am having a very difficult time finding a way to copy an excel document from one location in SharePoint to Another location in SharePoint. I hope someone can help me with this. I currently have a code that can copy a file from a network drive to another network drive but no idea how to do this within SharePoint.
Here is the information:
Source file location on SharePoint: https://mygroup.sharepoint.com/sites/MyStorageTestGroup1/Shared Documents/Marcos Sheet/OPS Forms
Destination location on SharePoint: https://mygroup.sharepoint.com/site... Documents/Marcos Sheet/Quality Records/Q4169
Source File Name: OPS 097 Rev 6 Non Conformance Report.xlsx
Below is my code but I honestly have no idea if I am even close or if I am even missing a "/" or something simple.
Any help would be appreciated
Here is the information:
Source file location on SharePoint: https://mygroup.sharepoint.com/sites/MyStorageTestGroup1/Shared Documents/Marcos Sheet/OPS Forms
Destination location on SharePoint: https://mygroup.sharepoint.com/site... Documents/Marcos Sheet/Quality Records/Q4169
Source File Name: OPS 097 Rev 6 Non Conformance Report.xlsx
Below is my code but I honestly have no idea if I am even close or if I am even missing a "/" or something simple.
Any help would be appreciated

VBA Code:
Private Sub Transfer_NCR()
Dim sDocPath As String
Dim sFileName As String
Dim sTargetPath As String
Dim sSourcePath As String
Dim sDriveLetter As String
Dim network As Object
Dim folderPath As String
Dim folderName As String
Dim driveLetter As String
Dim fs As Object
' Create instance of WScript.Network object
Set network = CreateObject("WScript.Network")
' Specify the SharePoint site URL
Dim sharepointURL As String
sharepointURL = Workbooks("Quality Log").Sheets("List").Range("C29").Value
' drive letter should be available (not mapped to a share already, to avoid error '80070055 - The local device is already in use')
sDriveLetter = "R:"
' Map the SharePoint document library to a network drive
On Error Resume Next
network.MapNetworkDrive driveLetter, sharepointURL
If Err.Number <> 0 Then
MsgBox "Failed to map network drive. Error: " & Err.Description, vbCritical
GoTo UnmapDrive
End If
On Error GoTo 0
sFileName = Workbooks("Quality Log.xlsm").Sheets("List").Range("C32").Value
Set fs = CreateObject("Scripting.FileSystemObject")
sDocPath = ThisWorkbook.path
network.MapNetworkDrive sDriveLetter, sDocPath
sSourcePath = sDriveLetter & Workbooks("Quality Log.xlsm").Sheets("List").Range("C30").Value & "/" & sFileName
Debug.Print Workbooks("Quality Log.xlsm").Sheets("List").Range("C30").Value & sSourcePath
sTargetPath = sDriveLetter & Workbooks("Quality Log").Sheets("List").Range("C34").Value & "/" & sFileName
Debug.Print Workbooks("Quality Log").Sheets("List").Range("C31").Value & sTargetPath
fs.CopyFile sSourcePath, sTargetPath, True
network.RemoveNetworkDrive sDriveLetter
UnmapDrive:
'Unmap the network drive
network.RemoveNetworkDrive sDriveLetter, True, True
Set network = Nothing
Set fs = Nothing
End Sub
Quality Log.xlsm | |||
---|---|---|---|
C | |||
29 | https://mygroup.sharepoint.com/sites/MyStorageTestGroup1/Shared%20Documents/Marcos%20Sheet | ||
30 | https://mygroup.sharepoint.com/sites/MyStorageTestGroup1/Shared%20Documents/Marcos%20Sheet/OPS%20Forms | ||
31 | https://mygroup.sharepoint.com/sites/MyStorageTestGroup1/Shared%20Documents/Marcos%20Sheet/Quality%20Records/Q4169 | ||
32 | OPS 097 Rev 6 Non Conformance Report.xlsx | ||
33 | Q4169 | ||
34 | /Quality%20Records/Q4169 | ||
List |