none
Setting focus to a content control RRS feed

  • Question

  • Hi, I'm new to the pleasures of Word VBA. I have a form that the user keys in which in turn populates the Word document with the user entered values. Once submitted, I would like the focus to be at a certain point in the document. I know that for standard textboxes this can be achieved by using the SetFocus method.

    This doesn't seem to be available for content controls though. I would like to avoid using bookmarks as I believe people are moving more towards content controls. I suppose I have a couple of questions:

    1. Should I use content controls to accomplish this? If not how/what should I use?

    2. If content controls is the way forward for these kinds of problems, how can I set the focus to the content control?

    Thanks!

    Thursday, October 2, 2014 1:24 PM

Answers

  • If you want to position the insertion point in a particular content control, give that content control a title or tag, then use the SelectContentControlsByTitle or SelectContentControlsByTag method to access it.For example:

    ActiveDocument.SelectContentControlsByTitle("MyTitle").Item(1).Range.Select

    ActiveDocument.SelectContentControlsByTag("MyTag").Item(1).Range.Select


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by Dan Rooney Friday, October 3, 2014 10:06 AM
    Thursday, October 2, 2014 9:02 PM

All replies

  • If you want to position the insertion point in a particular content control, give that content control a title or tag, then use the SelectContentControlsByTitle or SelectContentControlsByTag method to access it.For example:

    ActiveDocument.SelectContentControlsByTitle("MyTitle").Item(1).Range.Select

    ActiveDocument.SelectContentControlsByTag("MyTag").Item(1).Range.Select


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by Dan Rooney Friday, October 3, 2014 10:06 AM
    Thursday, October 2, 2014 9:02 PM
  • Thanks you again Paul, you've saved my life this week :)
    Friday, October 3, 2014 10:06 AM