7

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

8
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
0

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

Creating a reference of Microsoft Scripting Runtime Library

-1

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.

https://support.microsoft.com/en-gb/kb/2616712

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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