2017-11-22 4 views
0

のSharePointへのローカルファイルをコピーするFileCopyを使用している間、私はエラーにVBA - ランタイムエラー52

実行時エラー52、不正なファイル名または番号

を取得しています。

私は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

更新

実行時エラー52

+1

これは前の質問と同じですが、パスにはファイル名を含める必要があります。しかし私はシェアポイントに慣れていないので、これが唯一の問題かどうかはわかりません。 – newacc2240

+0

こんにちは、私はファイル名を今回 'Call FileCopy(copyPath&" testing.xlsm "、SharePointLib)'に含めて、ファイルが存在することを確認しました – aaa

+0

あなたはフォルダではなくSP URLにコピーしようとしています。 \\ spserver \ lib \ filesのようなSPのフォルダライブラリのuncパスにコピーするか、またはファイルをアップロードするためにSP Webサービスを使用する必要があります。 – LocEngineer

答えて

1

聖なるキバナノギョウジャニンニクのドライブをマップし、新しいパスZ:\Test Folder - New Formatを得るが、まだヒット、ヘルプみんなのためのおかげで、newacc2240 @正しかったです。私はこの例を見て、問題を見つけました。

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

だから、私はちょうどSharePointLibに私のファイル名を追加する必要があるため。

以前は、ファイル名が添付されたソースからコピー先にファイルがコピーされると想定したため、何時間もストレスを感じました。

関連する問題