C# Word Interop ActiveX Controls
Hi,
I am trying to programmatically list all the MSForms, UserForms, etc. in a set of Word documents, as well as the values of their properties.
I found multiple posts on this topic to list controls in the document, however I am trying to list the ones that are in the "Developer" tab.
As such the only matching post would be this one, but I couldn't get the same code working (no "items" in ContentControls and when I try to list it in the same way, the returned collection is empty).
Other solutions I found used Interop to iterate over the document FormFields/Shapes/InlineShapes/Bookmarks, which returned 0 results in my case. I also tried the InvokeMember method, it also did not return anything useful for my specific use case. Finally, I also tried to iterate over the ContentControls but I only get an empty ContentControls collection.
I also tried to access the ContentControls using VSTO instead of Interop but could not cast the Microsoft.Office.Interop.Word.Document to a Microsoft.Office.Tools.Word.Document. Though I am very new to the Microsoft world and still don't understand all the subtleties (Interop PIA vs. VSTO (in the documentation VSTO uses Interop to open the document and it seems like they have a lot of interfaces in common), Office.Forms vs. vbext_ct_MSForm, etc.).
I attached a screenshot of what I would like to extract in a test document. Ideally I would be able to extract all the "Properties" and their associated values (bottom left) for each ActiveX Control (TextBox1 in the screenshot), that are embedded in each MSForm (top left, UserForm1 in the screenshot). At the top of the document I also added a few macros to show how I would access those values in VBA inside the document. I would like to get the same result, but from C#.
Thanks, J.