VBA code to upload text file with credentials

nbajaj

New Member
Joined
Nov 16, 2017
Messages
1
I have managed to put together below code to upload a text file to sharepoint. However it throws a permission denied error even when I manually login to sharepoint first and then run this code. Can someone help me? I can enter credentials if I get a way to do that. Best solution would be to ask user to enter his own credentials so that the same gets reflected on sharepoint. Appreciate any help on this!

Sub UploadToSharepoint()
Dim SharepointAddress As String
Dim LocalAddress As String
Dim objNet As WshNetwork
Dim FS As Object
SharepointAddress = "some address
<sharepoint slashes="" backward="" with="" replaced="" forward="" and="" removed="" is="" word="" http="" where="" path=""></sharepoint>"
LocalAddress = "some address
<detailed name="" with="" included="" file="" address="" local="">"
Set objNet = New WshNetwork
Set FS = New Scripting.FileSystemObject
objNet.MapNetworkDrive "Z:", SharepointAddress
If FS.FileExists(LocalAddress) Then
FS.CopyFile LocalAddress, SharepointAddress
End If
objNet.RemoveNetworkDrive "Z:", SharepointAddress
Set objNet = Nothing
Set FS = Nothing
End Sub
</detailed>
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,216,105
Messages
6,128,859
Members
449,472
Latest member
ebc9

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