【问题标题】:VBA Sharepoint Check In File after Upload上传后的 VBA Sharepoint 签入文件
【发布时间】:2021-09-20 20:43:02
【问题描述】:

使用此代码将文件上传到 SharePoint 有一段时间了,前几天注意到上传文件时,它会自动签出给我自己,必须进入 SharePoint 并手动签入,以便其他人可以查看文件。有什么方法可以修改或添加到下面的代码以在文件上传后自动签入文件?完全被难住了,任何帮助将不胜感激。

Sub SharePointUpload()

Dim WSN
Dim spAdd

Set WSN = CreateObject("WScript.Network")
spAdd = "https://mysharepoint/test"
WSN.mapnetworkdrive "N:", spAdd

ActiveWorkbook.Save

Dim SharepointAddress As String
Dim LocalAddress As String
Dim objNet As Object
Dim FS As Object

' Where you will enter Sharepoint location path
SharepointAddress = "\\mysharepoint\test"
' Where you will enter the local file path
LocalAddress = "C:\data\sample_file.xlsm"
Set objNet = CreateObject("WScript.Network")
Set FS = CreateObject("Scripting.FileSystemObject")
If FS.FileExists(LocalAddress) Then
FS.CopyFile LocalAddress, SharepointAddress
Else: MsgBox "File does not exist!"
End If

Set objNet = Nothing
Set FS = Nothing

WSN.removenetworkdrive "N:"

End Sub

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    即使关闭了选项 Require Check Out,我的 SharePoint 文档库也遇到了同样的问题 - 一些文档(Word、Excel)被自动上传为签出(绿色箭头标记),而其他文档则是实际上签入来自上传。此外,当我想手动签入此类文档时,我收到有关缺少必填字段的错误消息,尽管库中没有设置为必填字段。

    在我的情况下,原因是字段Title。此字段作为默认文本字段显示在库中,并且也显示在 Office 文件中。我注意到对于带有空字段 Title 的 Office 文件,该文档在上传过程中会自动检出。当上传的文档在Title 属性中包含一些文本时,没有设置签出。我还尝试使用工作流更改Title,然后签出文件(创建后),但它不起作用 - 需要初始签入才能启动工作流。手动更改文档属性是可行的,但这太乏味了...

    处理此问题的第一个编程选项可能是在为空时填充上传文档的 Title 属性(即添加文件名或任何其他文本)。应该适用于多种语言。 Python 示例:

    from docx import Document
    
    path = 'D:/myfile.docx'
    document = Document(path)
    document_property = document.core_properties
    if not document_property.title:
        document_property.title = 'Everything is Awesome'
    document.save(path)  
    

    在 VBA 中 Title 应该可以通过 Wb.BuiltinDocumentProperties("Title") 访问。

    对我来说另一个成功的选择是在文档库的列中找到列 Title 并将其重命名为其他名称(我使用 Titlex 作为新名称),然后尝试上传带有空标题的新文档 - 这次在那里上传的文档没有自动签出。然后我可以将Titlex 设置回Title 而不返回问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-25
      • 2019-01-07
      • 2015-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-04
      相关资源
      最近更新 更多