excel - 上传后的 VBA Sharepoint checkin 文件

标签 excel vba

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

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

最佳答案

即使使用选项 Require Check Out,我的 SharePoint 文档库也有同样的问题。关闭 - 一些文档(Word、Excel)被自动上传为 checkout (绿色箭头标记),而其他文档实际上是通过上传 checkin 的。此外,当我想手动 checkin 此类文档时,我收到有关缺少必填字段的错误消息,尽管库中没有设置为必填字段。
在我的情况下,原因是字段 Title .此字段作为默认文本字段显示在库中,并且也显示在 Office 文件中。我注意到对于带有空字段的 Office 文件 Title文件在上传过程中自动 check out 。当上传的文档在 Title 中包含一些文本时属性,没有设置 checkout 。我还尝试使用工作流来更改 Title然后 checkout 文件(创建后),但它不起作用 - 需要初始 checkin 才能启动工作流程。手动更改文档属性是可行的,但这太乏味了……
处理此问题的第一个程序选项可能是填写 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 作为新名称),然后尝试上传带有空标题的新文档 - 这次上传的文档没有自动 checkout 。然后我可以设置Titlex返回 Title不返回问题。

关于excel - 上传后的 VBA Sharepoint checkin 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63604658/

相关文章:

VBA countif 语句只返回 0

c++ - 从 VBA Excel 调用 SAP 客户端

excel - 在 Excel 中使用条件格式宏跳过空格

xml - 如何在 VBA Excel 2003 中解析 XML?

xml - 如何在由 XSLT 转换为 Excel 工作表的 XML 标记/元素中包含空格

vba - Excel - 如何在 Workbook_Open 事件上创建按钮

vba - 在 PowerPoint 中重命名对象

python - 强制 Pandas 保留多个同名列

VBA - 如何将选定的范围传递给 TextBox 作为引用?

regex - 即使匹配不需要,VBScript 正则表达式也会填充子匹配