[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 24
  • Last Modified:

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.
Example
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.
0
hindersaliva
Asked:
hindersaliva
  • 4
  • 3
1 Solution
 
EirmanChief Operations ManagerCommented:
Does manual updating work? (F9)
0
 
hindersalivaAuthor Commented:
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

0
 
GrahamSkanRetiredCommented:
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.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
GrahamSkanRetiredCommented:
Oops. cross-posted.
SelectContentControlsByTag returns a collection, so try
ActiveDocument.SelectContentControlsByTag("Status")(1).Text = "Hello

Open in new window

"
0
 
GrahamSkanRetiredCommented:
Select the control and click Properties in the Developer tab to see the Tag and Title names
0
 
hindersalivaAuthor Commented:
Graham, I have attached a piece of the document. See the 'box' [Status]
Sample.docx
0
 
GrahamSkanRetiredCommented:
Thanks. That has settled it. I was careless about the correct property to use. This works:
Activedocument.SelectContentControlsByTag("Issue Status")(1).Range.Text = "Hello"

Open in new window

0
 
hindersalivaAuthor Commented:
Brilliant Graham. Thanks!
0

Join & Write a Comment

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now