Link to home
Start Free TrialLog in
Avatar of hindersaliva
hindersalivaFlag for United Kingdom of Great Britain and Northern Ireland

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.
User generated image
I tried this
ActiveDocument.FormField("Issue status").Result = "Hello"

Open in new window


But I get 'object doesn't support this property or method'.

What am I doing wrong?

Thanks.
Avatar of Eirman
Eirman
Flag of Ireland image

Does manual updating work? (F9)
Avatar of hindersaliva

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.
ActiveDocument.SelectContentControlsByTag("Status").Text = "Hello"

Open in new window

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:
ActiveDocument.FormFields("IssueStatus").Result = "Hello"

Open in new window

If it's just a bookmark without being a FormField name then
ActiveDocument.Bookmarks("IssueStatus").Range.text= "Hello"

Open in new window

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
ActiveDocument.SelectContentControlsByTag("Status")(1).Text = "Hello

Open in new window

"
Select the control and click Properties in the Developer tab to see the Tag and Title names
Graham, I have attached a piece of the document. See the 'box' [Status]
Sample.docx
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Brilliant Graham. Thanks!