簡體   English   中英

VBA-運行時錯誤52

[英]VBA - runtime error 52

我遇到了錯誤

運行時錯誤52,文件名或數字錯誤

同時使用FileCopy將本地文件復制到共享點。

我按照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網站后,我從窗口資源管理器復制路徑。

駕駛

更新

映射驅動器並獲取新的Path Z:\\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

以前,我假設它會將帶有附件文件名的文件從源復制到目標,這使我承受了數小時的壓力。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM