2015-12-02 101 views
1

我想製作一個插件來更新word文檔屬性。我已經準備好使用插件/功能區等,因爲我有其他功能正在工作。我使用MSVS嚮導來創建單詞ribbon項目。VB 2013,修改word文檔屬性/自定義屬性

我被困在如何;訪問活動的Word文檔,並訪問屬性/自定義屬性。我無法弄清楚;聲明,調用,庫等等。我無法使任何MSDN示例工作...。我完全錯過了一些東西。

例如:'ActiveDocument.CustomDocumentProperties'不起作用。

免責聲明 - 我不是編碼員。我有這一切與VBA工作,我試圖將其移交給VB。我還在閱讀已發佈的幫助,並嘗試使用示例。

任何建議,將不勝感激。親切的問候,

回答

0

瞭解了一些。 我不再需要:

Imports moDoc = Microsoft.Office.Interop.Word 

使用Office.Core。而不是Office.Core.Interop

Dim Prop As Microsoft.Office.Core.DocumentProperty 
Dim oBuiltInProperties As Microsoft.Office.Core.DocumentProperties 
Dim oCustomProperties As Microsoft.Office.Core.DocumentProperties 

oBuiltInProperties = DirectCast(Globals.DocSelect.Application.ActiveDocument.BuiltInDocumentProperties, Microsoft.Office.Core.DocumentProperties) 
oCustomProperties = DirectCast(Globals.DocSelect.Application.ActiveDocument.CustomDocumentProperties, Microsoft.Office.Core.DocumentProperties) 

For Each Prop In oBuiltInProperties 
    'do stuff 
    Prop.Name = sx 
    sy=Prop.Value.ToString 
next 

'create properties 
sx="New Property" 
sy="New Property Value" 
oCustomProperties.Add(sx, False, Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString, sy) 

現在所有的作品。

0

我明白了。

模塊聲明外:

Imports moDoc = Microsoft.Office.Interop.Word 

內分 - 此相關聯的開放式應用程序與對象:

Dim mocCustProperties As Microsoft.Office.Core.DocumentProperties 
Dim odpProp As Office.DocumentProperty 

Dim oActiveApp As moDoc.Application 
oActiveApp = GetObject(, "Word.Application") 

我們作爲文檔打開的應用關聯

現在odpProp是一個可讀/添加屬性:

For Each odpProp In mocCustProperties 
    If odpProp.Name = 「something」 Then 
    ‘do dtuff 
    End If 
Next 

必須通過將活動文檔引用爲文檔而不是應用程序來實現此目的,但我無法完成此工作。 乾杯,

0

Drat - 錯過了上面的幾行 - 請忽略。

我明白了。 模塊外部聲明:

Imports moDoc = Microsoft.Office.Interop.Word 

內分,這與對象

Dim oActiveApp As moDoc.Application 
oActiveApp = GetObject(, "Word.Application") 
oDocCustomProperty = oActiveApp.ActiveDocument.CustomDocumentProperties 

我們打開應用程序的文件關聯相關的開放式應用程序

Dim mocCustProperties As Microsoft.Office.Core.DocumentProperties 
Dim odpProp As Office.DocumentProperty 
mocCustProperties = CType(oDocCustomProperty, Office.DocumentProperties) 

現在odpProp是可讀/添加propoeties

For Each odpProp In mocCustProperties 
    If odpProp.Name = 「something」 Then 
    ‘do dtuff 
    End If 
Next