How to create ContentControls in VBA to syn with SharePoint Columns

Frequent Visitor

I have a SharePoint library where I want to convert thousands of documents offline, and programmatically create Content Controls that sync with the SharePoint columns.

 

The method in VBA to create a ContentControl is defined here:

https://docs.microsoft.com/en-us/office/vba/api/word.contentcontrols

 

I have succeeded in creating the ContentControls, but they do not sync with SharePoint when the documents are moved to the library. If I create the same ContentControls via menu options (Insert - Quick Parts - Document Property), they do sync with SharePoint. The Document must be loaded into SharePoint at some time in it's life to have the correct property names available in the Document Property menu.

 

I have examined the XML of the two types of document, one with CT created via menu and one with CT created using VBA. The XML is not the same. When the CT is created via menu options, the XML contains much more data relating to the CT.

 

So just creating and naming a CT via VBA is not sufficient. I have also experimented with VBA methods for setting XML mapping of the CT, but it did not make any difference. In any case, there are other XML "files" that seem to be needed, but are not created by VBA.

 

(By files, I mean files that are apparent when the Word document is converted into a Zip, to reveal all of the component XML files)

 

This has been quite frustrating because I have spend a lot of time experimenting and researching. I did not find any source that explains how to create a CT using VBA, so that it will sync with SharePoint. Where can I find such information?

0 Replies