Excel Error for Sharepoint MapNetworkDrive

Using Excel 2013, I am trying to upload an excel file to sharepoint using the method below. I seem to have a problem displaying my network drive, the error I get is the "The specified device name is not valid" on the line objNet.MapNetworkDrive "A: ", sFolder.

Any help in this matter is welcome - in advance.

Sub nlsharepoint()

Dim sFolder As String
Dim sFileName As String
Dim locFolder
Dim objNet As Object
Dim FS As Object

sFolder =  "\\company.sharepoint.com\sites\company\Documents\Morning%20Reports\"
sFileName = "New Line Tracker 2.xlsx"
locFolder = "C:\User\Desktop\NewLinesOutput.xlsx"

Set objNet = CreateObject("WScript.Network")
Set FS = CreateObject("Scripting.FileSystemObject")
objNet.MapNetworkDrive "A: ", sFolder

If FS.fileexists(locFolder) Then
FS.copyfile locFolder, sFolder
End If

objNet.RemoveNetworkDrive "A:"
Set objNet = Nothing
Set FS = Nothing
End Sub
+1
source share
1 answer

I am sure this is correct, but it seems simple, so if you do not tell me, I will delete it.

I believe you need to replace this line:

objNet.MapNetworkDrive "A: ", sFolder

with this:

objNet.MapNetworkDrive "A:", sFolder

There will be a space after you specify the drive to display, and I do not believe what it should be.

+1

All Articles