VB 2013, change the Word property property / custom property

advertisements

I wish to make an add-in to update word document properties. I’m all ready to go with the addin / ribbon / etc. as I have other ribbon functions that are working. I used the MSVS wizard to create the word ribbon project.

I’m stuck on how to; access the active word document, and access the properties/custom properties. I can’t figure out the; declarations, calls, library, etc. I have not been able to make any of the MSDN samples work…. I’m totally missing something.

For example: ‘ActiveDocument.CustomDocumentProperties’ does not work.

Disclaimer - I’m not a coder. I had this all working with vba, I’m trying to port it over to vb. I’m also still reading through the posted help, and trying samples.

Any suggestions would be appreciated. Kind regards,


I got it figured.

Outside the module declare:

Imports moDoc = Microsoft.Office.Interop.Word

Within the sub - This associates the open app with an object:

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

Now to associate the open app as a document:

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

Now odpProp is an available to read/add properties:

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

There must be a way to do this by referencing the active document as a document rather than an application, but I was unable to make this work. Cheers,