Copy Multiple Files from Absolute Paths to SharePoint with Same File Names

KimP

New Member
Joined
Dec 3, 2019
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi,

Firstly, I apologise if this has been answered multiple times but my google searches, although provided ideas, have produced as many questions as answers.

In the Excel file where the code resides, I have an excel table that has a list of absolute file paths (SharePoint). They are in various folders and sub-folders.


File
https://domain.sharepoint.com/sites/site/Shared Documents/FolderA/FolderB/File1.xlsx
https://domain.sharepoint.com/sites/site/Shared Documents/FolderA/FolderB/FolderC/File1.csv
https://domain.sharepoint.com/sites/site/Shared Documents/FolderA/File2.xlsx
https://domain.sharepoint.com/sites/site/Shared Documents/FolderD/FolderE/File3.xlsx
https://domain.sharepoint.com/sites/site/Shared Documents/FolderZ/FolderY/File2.csv


I would like to copy these files to a destination folder (SharePoint) with the same file names.
Before copying the files I need to check if the folder path exists and create it if it doesn't.

I have gotten around some of the SharePoint issues by mapping the site as a network drive with:
VBA Code:
Sub MapDrive()

Set WshNetwork = CreateObject("WScript.Network")

On Error Resume Next
WshNetwork.RemoveNetworkDrive "A:"
On Error GoTo 0

WshNetwork.MapNetworkDrive "A:", "https://domain.sharepoint.com/sites/site/Shared Documents/FolderA"

'WshNetwork.RemoveNetworkDrive "A:"

Set WshNetwork = Nothing

End Sub

Now this is where I show my lack of VBA skills but I think it gives the general idea of what I'm trying to achieve. The 'For' loop is likely completely wrong and I have nothing in there yet for checking the folder path/creation.

VBA Code:
Sub CopyFiles()


Dim Files As Variant
Dim FSO As Object
Dim DPath As String

Application.DisplayAlerts = False
Application.ScreenUpdating = False


Set Files = Application.Transpose(Range("FileList"))
Set DPath = Range("PathToSaveReports").Value

For Each f In Files
Set FSO = CreateObject("scripting.filesystemobject")
Set FName = FSO.GetBaseName
Set FPath = FSO.GetAbsolutePathName
f = FSO.CopyFile(FPath, DPath & "/" & FName)

Next f

Set FSO = Nothing

Application.DisplayAlerts = True
Application.ScreenUpdating = True


End Sub

Hopefully I've provided enough detail. Any suggestions appreciated.

Thanks,
Kim

EDIT:
I should have mentioned, also posted here: Copy Multiple Files from Absolute Paths to SharePoint with Same File Names
 
Last edited by a moderator:

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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