我有这个代码通过将其映射到驱动器来将我的文档上传到sharepoint。但是,在我甚至运行代码之前,我得到一个“编译错误,Sub或函数未定义”。然后它突出显示此行的第二个引号:objNet.MapNetworkDrive“A:”,SharepointAddress
以下是整个Sub例程。所有的帮助和评论表示赞赏。提前谢谢!
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
答案 0 :(得分:1)
您所在的引号在相关区域看起来有点奇怪:”
。
删除”
并将其替换为您用于"
变量的shapepointaddress =...
。
答案 1 :(得分:0)
我希望:
SharepointAddress = "\\share.deere.com\teams\sm_at_sd\suppcaptracking\Test"
答案 2 :(得分:0)
我遇到了类似的挑战。导出文件不起作用。为了更正代码格式和间距中的错误,我创建了一个子程序来执行此操作。它在我的机器上运行良好。
这个子有四个参数:文件名、文件现在所在的路径、共享点文件夹的路径和临时映射网络驱动器的可选参数(如果在机器上使用 A) .
Public Sub uploadFileToSP(filename As String, localPath As String, sharePath As String, Optional tempdrive As String = "A:")
Dim ObjNet As Object, FS As Object
Set ObjNet = CreateObject("WScript.Network")
Set FS = CreateObject("Scripting.FileSystemObject")
If FS.FileExists(localPath & Application.PathSeparator & filename) Then
ObjNet.MapNetworkDrive tempdrive, sharePath
FS.CopyFile localPath & Application.PathSeparator & filename, tempdrive & Application.PathSeparator & filename
ObjNet.RemoveNetworkDrive tempdrive
Set ObjNet = Nothing
End If
End Sub
这是调用子程序的示例
Call uploadFileToSP("myImage.JPG", "D://my/path", "https://my/sharepoint/path", "A:")