hindersaliva
asked on
Word VBA updating a 'Field'
On a Word document I need to programatically update (what looks like a) Field with VBA. But I'm not sure whether they are Fields, as Fields have curly brackets, not square ones. See here.
I tried this
But I get 'object doesn't support this property or method'.
What am I doing wrong?
Thanks.
I tried this
ActiveDocument.FormField("Issue status").Result = "Hello"
But I get 'object doesn't support this property or method'.
What am I doing wrong?
Thanks.
Does manual updating work? (F9)
ASKER
Eirman, it's a placeholder that I need to update from some textboxes on a UserForm.
No, F9 would do nothing.
I now think these are Content Controls.
I'm thinking I should be able to update it like this. But it's not right, because the intellisense doesn't come up.
No, F9 would do nothing.
I now think these are Content Controls.
I'm thinking I should be able to update it like this. But it's not right, because the intellisense doesn't come up.
ActiveDocument.SelectContentControlsByTag("Status").Text = "Hello"
It might be a bookmark. If so, and if it's name is "IssueStatus" ("Issue Status" is illegal as a bookmark name) then try, after adding an 's' to FormField:
Note that you can use Find/GoTo to see the bookmark names in the document. Also Alt+F9 with toggle the display of fields in the Selection between result and code.
ActiveDocument.FormFields("IssueStatus").Result = "Hello"
If it's just a bookmark without being a FormField name thenActiveDocument.Bookmarks("IssueStatus").Range.text= "Hello"
If that doesn't work either, post a non-confidential sample.Note that you can use Find/GoTo to see the bookmark names in the document. Also Alt+F9 with toggle the display of fields in the Selection between result and code.
Oops. cross-posted.
SelectContentControlsByTag returns a collection, so try
SelectContentControlsByTag
ActiveDocument.SelectContentControlsByTag("Status")(1).Text = "Hello
"
Select the control and click Properties in the Developer tab to see the Tag and Title names
ASKER
Graham, I have attached a piece of the document. See the 'box' [Status]
Sample.docx
Sample.docx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Brilliant Graham. Thanks!