1

I have searched high and low on stackexchange and other sites (vbaexpress, MSDN, etc...). There is extensive dialog around this, I have tried most of the examples, and still nothing is working.

Scenario:

  • User clicks 'Create Report' button in Access.
  • vba creates a new instance of a Word doc from the default template associated with a SharePoint library.
  • The Word template is formatted with tables and bookmarks to accept data, AND already has a number of custom property fields stored (NULL at this time)
  • vba pulls data from tables (tables are linked to SharePoint lists) and populates the entire Memo.
  • the code then saves the new document to the SP library (same one with the template) and checks it in.

All of this works fine.

The vba also includes the code to store both built-in and the custom properties: example of the code:

Set objWord = CreateObject("Word.Application")  
Set objDoc = objWord.Documents.Add(tName)  
objWord.Visible = True

objDoc.BuiltinDocumentProperties("Title") = "2040"

With objDoc.CustomDocumentProperties  
      .Add name:="DocLevel", _  
          LinkToContent:=False, _  
          Type:=msoPropertyTypeString, _  
          Value:="Confidential"  
      .Add name:="UserDiscipline", _  
          LinkToContent:=False, _  
          Type:=msoPropertyTypeString, _  
          Value:="Broker"  
  End With  

objDoc.SaveAs (fPath)
objDoc.CheckIn

Also, assuming that the properties are already objects in the template, I tried this just setting without the .Add:

objDoc.CustomDocumentProperties name:="DocLevel", LinkToContent:=False, _  
            Type:=msoPropertyTypeString, Value:="Confidential"

Everything works - EXCEPT - the custom doc properties are not saved. Even the built ones are saved - but not the custom ones.

I have the MS Office 14.0 Object Library, 14.0 Access library and VB for extensibility included. Is there some other reference that I need?

Thanks in advance to the Overflow community for any help...

2 Answers2

2

And The answer is....

There is a completely different method available for this: ContentTypeProperties!

'customdocumentproperties' are properties of the Word document. Since this was an attempt to supply custom content to the SharePoint library, a different method was required:

doc.ContentTypeProperties("UserDiscipline").Value = "Broker"

Posting this so hopefully others here won't have to redo this same research.

0

I have come across the similar issue in Word using VSTO: the custom document properties are there before you close Word but they cannot be saved. I tried to use ContentTypeProperties instead as user3662334 suggested however I cannot access ContentTypeProperties at all due to the following exception "This document must contain Content Type properties. Content Type properties are a common requirement for files in a document management system."

The solution I have found is extremely simple: you just need to update the document content slightly (e.g. add a space in the end of the text) and save the document:

document.Content.Text += " ";
document.Save();
yangli.liy
  • 101
  • 3
  • 5