I'm looking for a snippet in VBA to upload a document (PDF file) into SharePoint online

3 Answers 3

Dim SharepointAddress As String
Dim LocalAddress As String
Dim objNet As Object
Dim FS As Object

' Where you will enter Sharepoint location path
SharepointAddress = "\\sharepoint path to document library"  & "\" 
 ' Where you will enter the file path, ex: Excel file
LocalAddress = "your file path"                                     
Set objNet = CreateObject("WScript.Network")
Set FS = CreateObject("Scripting.FileSystemObject")
If FS.FileExists(LocalAddress) Then
FS.CopyFile LocalAddress, SharepointAddress
End If
Set objNet = Nothing
Set FS = Nothing

Also, need to make sure "Microsoft Scripting Runtime Library" is turned on.

Creating a reference of Microsoft Scripting Runtime Library


Just to add I have recently used this solution and it worked. The hardest part was mapping the sharepoint to a network drive as I didn't have elevated permissions.

The link below helped with this.


I had much less luck with solutions found elsewhere which mapped and then removed network drives in the sub.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.