通过 VBA 将文件上传到 SharePoint

Upload File to SharePoint through VBA

我在一些论坛上看到过这段代码(或类似代码),但有些论坛没有这行映射:"objNet.MapNetworkDrive “A: ” , SharepointAddress"

computer/network 省略此代码是否安全?

Sub UploadToSharepoint()

Dim SharepointAddress As String
 Dim LocalAddress As String
 Dim objNet As Object
 Dim FS As Object
 SharepointAddress = "http://share.deere.com/teams/sm_at_sd/suppcaptracking/Test"

 LocalAddress = "c: MyWorkFiletoCopy.xlsx"

Set objNet = CreateObject(“WScript.Network”)

Set FS = CreateObject(“Scripting.FileSystemObject”)
 objNet.MapNetworkDrive “A: ” , SharepointAddress

If FS.FileExists(LocalAddress) Then
 FS.CopyFile LocalAddress, SharepointAddress
 End If

objNet.RemoveNetworkDrive “A: ”

Set objNet = Nothing

Set FS = Nothing

End Sub

这可能是更好的方法:

Sub UploadToSharepoint()

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

    SharepointAddress = "\share.deere.com\teams\sm_at_sd\uppcaptracking\Test"

    LocalAddress = "c:\blah\blah2\MyWorkFiletoCopy.xlsx"

    Set FS = CreateObject("Scripting.FileSystemObject")

    If FS.FileExists(LocalAddress) Then
        FS.CopyFile LocalAddress, SharepointAddress
    End If

End Sub

应该不需要映射驱动器。