VBA代码,用于获取Sharepoint文档库基于文档名称的元数据详细信息

时间:2016-01-26 19:05:45

标签: excel vba excel-vba sharepoint-2010

我有以下代码打开sharepoint 2010文档库的基于文件名的特定文档(库只有excelfiles),但我无法读取该文件的元数据。我尝试使用Builtin和自定义文档属性,但没有运气。

Sub OpenSharePointFile(StrSharePointUrl As String, strDocLibrary As String, FileNameWithExt As String)

Application.ScreenUpdating = False

Dim SPWorkbook  As Workbook
Dim this        As Workbook
Dim sh          As Shape


Application.DisplayAlerts = False
Set SPWorkbook = Workbooks.Open(StrSharePointUrl & strDocLibrary & "\" & FileNameWithExt)
Application.DisplayAlerts = True

Set this = ThisWorkbook
If SPWorkbook Is Nothing Then
    MsgBox "This product is not available"
    Exit Sub
Else

    'Copy Metadata
    'ThisWorkbook.Sheets(Sht_Input.Name).Range("C3").Value = SPWorkbook.BuiltinDocumentProperties("Title")
    'ThisWorkbook.Sheets(Sht_Input.Name).Range("C4").Value = SPWorkbook.BuiltinDocumentProperties("Business Unit")
    'ThisWorkbook.Sheets(Sht_Input.Name).Range("C5").Value = SPWorkbook.BuiltinDocumentProperties("ItemNo")
    'ThisWorkbook.Sheets(Sht_Input.Name).Range("C6").Value = SPWorkbook.BuiltinDocumentProperties("ECO Type")
    'ThisWorkbook.Sheets(Sht_Input.Name).Range("C7").Value = SPWorkbook.BuiltinDocumentProperties("ItemDescription")
    'ThisWorkbook.Sheets(Sht_Input.Name).Range("C8").Value = SPWorkbook.BuiltinDocumentProperties("Status")
    'ThisWorkbook.Sheets(Sht_Input.Name).Range("C9").Value = SPWorkbook.BuiltinDocumentProperties("CasmasUpdate")
    'ThisWorkbook.Sheets(Sht_Input.Name).Range("E3").Value = SPWorkbook.BuiltinDocumentProperties("LabelData")
    'ThisWorkbook.Sheets(Sht_Input.Name).Range("E4").Value = SPWorkbook.BuiltinDocumentProperties("SpqWhActive")
    'ThisWorkbook.Sheets(Sht_Input.Name).Range("E5").Value = SPWorkbook.BuiltinDocumentProperties("I2of5Label")
    'ThisWorkbook.Sheets(Sht_Input.Name).Range("E6").Value = SPWorkbook.BuiltinDocumentProperties("TiXHi")
    'ThisWorkbook.Sheets(Sht_Input.Name).Range("E7").Value = SPWorkbook.BuiltinDocumentProperties("SpecSent")
    'ThisWorkbook.Sheets(Sht_Input.Name).Range("E8").Value = SPWorkbook.BuiltinDocumentProperties("CasmasToYes")
    'ThisWorkbook.Sheets(Sht_Input.Name).Range("E9").Value = SPWorkbook.BuiltinDocumentProperties("EcoOwner")

    'Copy ECO Summary:
    ThisWorkbook.Sheets(Sht_Input.Name).Range("B12").Value = SPWorkbook.Sheets(Sht_Input.Name).Range("B12").Value

    'Copy Ref ID
    ThisWorkbook.Sheets(Sht_Input.Name).Range("D14").Value = SPWorkbook.Sheets(Sht_Input.Name).Range("D14").Value

    'Copy THIS ITEM
    SPWorkbook.Sheets(Sht_Input.Name).Range("C14:C74" & lRow).Copy
    ThisWorkbook.Sheets(Sht_Input.Name).Range("C14").PasteSpecial xlPasteValues

    'Delete from this workbook if available and Copy Shape if available in Sharepoint

    If ThisWorkbook.Sheets(Sht_LCEncodingInfo.Name).Shapes.Count = 2 Then
        For Each sh In ThisWorkbook.Sheets(Sht_LCEncodingInfo.Name).Shapes
                If sh.Name <> "Picture 1" Then
                    sh.Delete
                End If
        Next
    End If


    If SPWorkbook.Sheets(Sht_LCEncodingInfo.Name).Shapes.Count = 2 Then
        For Each sh In SPWorkbook.Sheets(Sht_LCEncodingInfo.Name).Shapes
                If sh.Name <> "Picture 1" Then
                    sh.Height = 150 ' 138.96 '1.93"
                    sh.Width = 150 ' 228.24 '3.17"
                    sh.Copy
                    Application.Goto ThisWorkbook.Sheets(Sht_LCEncodingInfo.Name).Range("F9")
                    ActiveSheet.Paste
                End If
        Next
        ThisWorkbook.Sheets(Sht_LCEncodingInfo.Name).Range("G2").Select
    End If


    'Activate Input sheet
    ThisWorkbook.Sheets(Sht_Input.Name).Activate
    ThisWorkbook.Sheets(Sht_Input.Name).Range("C3").Select

    Application.DisplayAlerts = False
    SPWorkbook.Close
    Application.DisplayAlerts = True


    MsgBox "Product Details fetched."

End If

Application.ScreenUpdating = True

End Sub

1 个答案:

答案 0 :(得分:0)

尝试使用ActiveWorkbook.ContentTypeProperties(&#34;您的专栏名称&#34;)
代替SPWorkbook.BuiltinDocumentProperties(&#34;您的专栏名称&#34;)