Log in

View Full Version : Selecting a field



YossiD
12-26-2024, 05:37 AM
I'm trying to write a macro that will select the next REF field in a document so I can apply a specific style. A recorded macro gave me this command to go to the next REF field:

Selection.GoTo What:=wdGoToField, Which:=wdGoToNext, Count:=1, Name:="REF"

That puts the cursor just before the field. Now I just need to select the field. I'm sure it's simple but I can't figure out how to do that.

macropod
12-26-2024, 01:16 PM
If you want to apply particular formatting to the field(s), why don't you just add a \* Charformat switch to them, along with formatting the 'R' in REF to suit? None of this requires the field to be selected.

macropod
12-26-2024, 02:01 PM
Cross-posted at: VBA to select a field in MS Word - Microsoft Community (https://answers.microsoft.com/en-us/msoffice/forum/all/vba-to-select-a-field-in-ms-word/acca2455-9503-4bde-b7bc-63a67e0cf49e)
Please read VBA Express' policy on Cross-Posting in Rule 3: http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_new_faq_item3