Tom37
Tom37

Reputation: 71

Excel to Sharepoint MapNetworkDrive error

Using Excel 2013, I'm trying to upload an excel file to sharepoint using the method below. I seem to be having an issue mapping my network drive, the error I get is "The specified device name is invalid" on the objNet.MapNetworkDrive "A: ", sFolder line.

Any help with the matter is appreciated- thanks 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

Upvotes: 1

Views: 1966

Answers (1)

Michael A
Michael A

Reputation: 9900

I'm sure this is right, but it seems to simple so if not let me know and I'll delete.

I believe that you need to replace this line:

objNet.MapNetworkDrive "A: ", sFolder

with this:

objNet.MapNetworkDrive "A:", sFolder

There's a space after you specify the drive to map, and I don't believe that there should be.

Upvotes: 1

Related Questions