excel - 尝试将文件上传到 SharePoint 时出现运行时错误 1004

标签 excel vba sharepoint

我正在尝试使用 VBA 将本地 xlsm 文件上传到 SharePoint Online。用户保存文件后,文件将自动上传到 SharePoint。
这个概念是在用户保存 xlsm 文件后,它会使用复制的文件创建一个新文件夹,并将文件夹中的复制文件上传到 SharePoint。上传后,该文件夹将被删除。
但是,由于以下原因,我无法将文件保存到文件夹中

Runtime error 1004


我检查了可能的原因,文件名/路径确实存在,文件夹已成功创建。
该文件未被其他程序使用,只有 excel 运行该文件。
该文件夹是新创建的,它是一个空文件夹,不包含同名文件。
enter image description here
我确实检查了所有路径,它们都是正确的。
这是我的代码
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.ActiveWorkbook.path
myPath = Application.ActiveWorkbook.FullName
SharePointLib = "https://company.com/folder/subfoler"
copyPath = folderPath + "\copyPath"
MsgBox "This is the folderPath = " & folderPath & vbNewLine & "This is the filepath = " & myPath & vbNewLine & "The copyPath is = " & copyPath

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

SharePointLib = SharePointLib & FileNameWithExt(myPath)
ThisWorkbook.SaveCopyAs (copyPath)

Exit Sub

loadFailed:
UploadToSharepoint = False

End Sub

最佳答案

您的 copyPath只是一个文件夹,但是SaveCopyAs的参数应该是带有文件名的完整路径。

尝试这个:ThisWorkbook.SaveCopyAs copyPath & "\filename.xlsx"

关于excel - 尝试将文件上传到 SharePoint 时出现运行时错误 1004,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47429362/

相关文章:

excel - 在 Excel 工作表之间移动数据

javascript - 隐藏仅包含 1 个元素的分组(在 Sharepoint 中)

c# - 将另一种语言转换为 powershell 或在 powershell 中使用该语言

excel - 如何从单独的 Excel 工作表 VBA 中删除最后一行

excel - 将值复制到单独的 Excel 工作表 VBA

excel - SharePoint 2013 导出到 Excel - "An unexpected error has occurred."

python - 我不知道为什么我得到一个空白的输出文件

excel - 在 Access 中嵌入生成的 Excel 图表

c# - 使用客户端对象模型在 SharePoint 文档库上创建文件夹

c# - 使用 SSIS 脚本任务读取 Excel 单元格值