Formfields.BookMarks.get_Item (). Checkbox.Value not working (automation word)

I am unsuccessfully trying to change the meaning of the word Checkbox (developer tab) using automation in C #. I tried different ways, but the only one that I always find when searching the Internet is:

find the name of the flag by clicking the properties of the flag when you are in developer mode.

object oCheckbox = "Checkbox_name" document_name.FormFields.get_Item(ref oCheckbox).CheckBox.Value = true/false; 

But whenever I execute the code, I get the following error (the collection request element does not exist), which means that in my document there is no flag with the name "Checkbox_name", if I understand correctly.

I also tried to check the box with the same name and execute:

document_name.BookMarks.get_Item(ref oCheckbox).CheckBox.Value , but it doesn't work either ...

+4
source share
1 answer

If you checked the box by clicking the checkbox indicated on the developer tab, I assume that you are using Word 2007 or later.

And, if so, what you pasted is not a form field, but a content control. Therefore, if you enter the following into the nearest window in the VBA editor:

 ?ActiveDocument.Content.FormFields.Count 

... he will print "0". If you try:

 ?ActiveDocument.Content.ContentControls.Count 

... it should print some number greater than zero, depending on how many of them you inserted.

To insert a check box in the old-style form field, click the Tool Folder icon next to the check box icon - this reduces the number of control types, including Legacy Forms and ActiveX Controls. Each group has a flag, but this is the first group ("Legacy Forms") that will create a flag that appears in the FormFields collection.

I would suggest using a content control if possible, since the old-style form fields may not be supported forever.

0
source

All Articles