VBA – 运行时错误52

我收到错误

运行时错误52,错误的文件名或数字

同时使用FileCopy将本地文件复制到共享点。

我跟随微软的文件和文件path和文件名多次,但可以find错误。

 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网站后,我复制窗口资源pipe理器的path。

驾驶

更新

映射驱动器并获取新pathZ:\Test Folder - New Format ,但仍然命中运行时错误52

圣莫里,谢谢你们的帮助,@ newacc2240是对的。 看这个例子后我发现了这个问题。

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

所以我只需要将我的文件名添加到SharePointLib

以前我认为它会将文件从源文件复制到目标文件的名称,这使我压力好几个小时。