VBA - 运行时错误52

时间:2017-11-22 09:17:07

标签: excel vba excel-vba sharepoint

我收到了错误

  

运行时错误52,错误的文件名或编号

使用FileCopy将本地文件复制到sharepoint。

我多次关注document from microsoft以及文件路径和文件名,但可能会发现错误。

Private Sub Workbook_AfterSave(ByVal Success As Boolean)

Dim UploadToSharepoint As Boolean

Dim SharePointLib As String
Dim myPath As String
Dim folderPath As String
Dim objNet As Object
Dim FS As Object
Dim copyPath As String
Dim copyFilePath As String

folderPath = Application.ThisWorkbook.path
myPath = Application.ThisWorkbook.FullName
MsgBox "This is the folderPath" & folderPath 'C:\Users\username\Desktop
MsgBox "This is the filepath" + myPath 'C:\Users\username\Desktop\testing.xlsm

SharePointLib = "Z:\Test Folder - New Format\"
copyPath = folderPath + "\copyPath\"
MsgBox "The copyPath is = " & copyPath 'C:\Users\username\Desktop\copyPath\

If Not FolderExists(copyPath) Then
    FolderCreate (copyPath)
End If

MsgBox "The file will be uploaded to this address: " + SharePointLib 'Z:\Test Folder - New Format\

ThisWorkbook.SaveCopyAs copyPath & "testing.xlsm"
Call FileCopy(copyPath & "testing.xlsm", SharePointLib)

Exit Sub

loadFailed:
UploadToSharepoint = False

End Sub

我将驱动器映射到SharePoint站点后,从窗口浏览器复制路径。

drive

更新

映射驱动器并获取新路径Z:\Test Folder - New Format,但仍然遇到运行时错误52

1 个答案:

答案 0 :(得分:1)

圣洁的莫莉,感谢帮助人员,@ newacc2240是对的。看完这个例子后我发现了问题。

FileCopy "C:\Source\test.txt", "C:\Destination\test.txt" 'Result: Copies file from "C:\Source" to "C:\Destination"

因此,我只需要将我的文件名添加到SharePointLib

以前我认为它会将文件从源文件复制到附加文件名的目的地,这会让我压力几个小时。