【问题标题】:Using VBA to read the metadata or file properties of files in a SharePoint doc library使用 VBA 读取 SharePoint 文档库中文件的元数据或文件属性
【发布时间】:2011-09-19 21:04:04
【问题描述】:

我在一个 SharePoint 网站上有几百个 Word 模板 (DOTX)。许多用户团队使用这些模板。

当用户需要自定义此文档时,他们单击 SharePoint 上的一个特殊链接以从他们选择的模板生成一个新文档 (DOCX)。此新文档文件始终需要“链接”回其在 SharePoint 上的模板文件。如果文档丢失了该链接,它将无法正常工作并被视为“损坏”。

当文档中断时,我需要重新建立指向 SharePoint 上正确模板的链接。以编程方式执行此操作很有意义,因此我可以将解决方案分发给我的团队。

我想给每个模板文件一个唯一的模板 ID(一个三位数字),存储在元数据或自定义文件属性中。当从模板生成新文档时,模板 ID 会自动延续到文档中,这样就设置好了。现在我只需要使用 VBA 扫描 SharePoint 文档库中的模板文件以查找匹配的模板 ID。找到后,我可以重新建立链接,一切都很好。

我基本上是在找这个:

Sub DocFixer()

Dim objTemplate as Template
Dim objBrokenDoc as Document

Set objBrokenDoc = ActiveDocument

For each objTemplate in "\\SharePoint\Template Library\".Templates
    If objTemplate.Properties("Template ID").Value = objBrokenDoc.Properties("Template ID").Value Then
        objBrokenDoc.AttachedTemplate = objTemplate.Path
        Exit For
    End If
Next

End Sub

...但是我在使用 VBA 读取 SharePoint 文档库内容而不实际打开内容时遇到了问题,因为使用这么多模板需要很长时间,而且对用户来说非常具有破坏性。

有什么想法吗?你能指出我正确的方向吗?

编辑:这是我的解决方案:

Sub Macro()

Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")

Dim objFile As Object
Dim objDSO As Object

For Each objFile In FSO.GetFolder("\\SharePoint\doc lib\").Files
    Set objDSO = CreateObject("DSOFile.OleDocumentProperties")
    objDSO.Open objFile.Path

    If objDSO.CustomProperties.Item("Template_ID") = ActiveDocument.CustomDocumentProperties("Template_ID").Value Then
        ActiveDocument.AttachedTemplate = objFile.Path
        End
    End If
Next

MsgBox ("No matching template found. Please attach the proper template manually."), vbCritical

End Sub

显然这利用了 DSOFile.dll (http://technet.microsoft.com/en-us/library/ee692828.aspx),但我不必添加引用?仍然对那部分感到困惑。

此外,这可能不适用于 https:// (SSL)。不过为我工作,所以我想我会分享。

【问题讨论】:

  • 只要确保您没有使用空格创建模板 ID,例如'模板 ID' 因为它被转换为内部名称的 'Template_x0020_ID'

标签: sharepoint vba metadata


【解决方案1】:

我将从 VBA 调用 SharePoint web services 开始。 在那里,您可以调用GetListItems,这将直接拉回具有正确 TemplateID 属性的文档。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多