How to search and replace using fields in Microsoft Word?

I have a Word document with fields of the reference sort that occur in the form "[field]. [Field]" - in other words, there is a period between the two fields. I want to globally replace this with a space.

Word offers a special character ^ d to search for fields, but for some reason, the query "^ d. ^ D" does not find anything. However, ". ^ D" does. Now the problem is: what will I specify as replacement text to save the field code? If you use regular expressions, I could use "Find what expression", for example \ 1, but with regular expression mode ("wild card"). ^ D is not allowed.

I think I could write a macro ...

+7
source share
6 answers

It’s usually best to look for a macro route when searching for fields, because, as you say, the search algorithm that uses Word does not work as you might expect with fields.

But if you know exactly what the fields contain, you can specify a search pattern that is likely to work (but not in wildcard mode).

For example, if you want to find pairs of fields of number number, for example

{ STYLEREF 1 \s }.{ SEQ Figure \* ARABIC \s 1 } 

(which will usually be the same set of fields in the document)

If you really need to look for the following:

 { STYLEREF 1 \s }.<any field> 

you can make sure that field codes are displayed and search

 ^d STYLEREF 1 \s ^21.^d 

or

 ^19 STYLEREF 1 \s ^21.^19 

If you need to be more precise, you can also specify a second field.

"^ d" only works to find the beginning of the field, not the end of the field.

It’s a pity that ^ w wants to find at least 1 space character, because otherwise it would be more reliable to search

 ^19^wSTYLEREF^w1^w\s^w^21.^19 

Perhaps someone knows how to get around this without using wildcards?

+2
source

Torzaburo, I suggest you do this with a macro. You can start by recording a macro, and then refine the processing steps in the macro.

First enable hidden characters by going to Home> Paragraph> to toggle the show / hide paragraph character. In addition, select all and switch field codes (right-click and select "Toggle Field Codes".

Open a new blank Word document in addition to the one you opened. You will use it later. Run a macro and find the field using "^ d" (field code), as you said.

When the field is found, copy only the text of the field in brackets, and not the full link to the field. So far, the macro still writes ALT + TAB to a new blank document and inserts the field code in plain text.

At this point, perform the necessary search processing and replace field codes. Select the processed field codes, copy, ALT + TAB back to the original document and paste back between the brackets {}.

Stop recording the macro. Add any additional custom processing to the VBA macro.

Select all and switch field codes again. Update field codes.

+2
source

I would like to add to the Bibadia solution.

An example of an index input field; we want to change the name we are saddened at.

  • Make sure that hidden formatting is displayed (toggled with SHIFT + CTRL + F8).
  • Make sure the wildcard option is not selected. To search for fields, use the field opening and closing code (optionally use ^ w for spaces, as Bibadia suggested):

      ^ 19 XE "Deo, John" ^ 21 
  • Replace does not recognize the bracket character of the field, but allows you to paste the contents of the clipboard .;). To do this, insert the correct entry in the text. CTRL + F9 to enter the field and type:

      XE "Doe, John" 
  • Select the field above and copy

  • Use

      ^ c 
    in the replacement field
  • Click Replace All

TA-dah!

+2
source

You do not need a macro. Just switch all field codes using Alt + F9. Then find and replace what you want to change. When replacement is complete, use Alt + F9 again to disable field codes.

+1
source

Lately, it's probably too late for Beth (sorry Beth). And that's not exactly what Beth was looking for. But for everyone who is interested ...

It seems that Beth may have created captions throughout the document using INSERT CAPTION (hence the presence of field codes). This means that these captions will (automatically) be created in the CAPTION style.

To globally replace the delimiter "." with a "" (space) in such headers, complete two steps:

[1] Go to REFERENCES | INSERT CAPTION REFERENCES | INSERT CAPTION , then press NUMBERING and replace SEPARATOR "." with "EM-DASH". This will replace all title separators for the selected label in the CAPTION window. If you have other tags used in the document (for example, FIGURE), select the remaining tags one by one and repeat this process.

[2] Do a search / replace to search for the special character "em-dash" (^ +) in the CAPTION style, replacing "". Press REPLACE ALL .

Voila!

NOTE. . This assumes that em-dash is not displayed in the subtitle text anywhere. If so, then you need to do a preliminary and post-fiddle so that these empirical touches are not affected by the global replacement above.

"Pre-fiddle" is to do a global search / replace between headers, replacing em-dash ("^ +") with some other line (for example, "EM-DASH") that never occurs in any signature text. Then you perform the change of delimiter as described above. Finally, the “post-fiddle” is to restore the em dashes that were in the signatures by doing a global replacement of the string “EM-DASH” with the actual em-dash character “^ +”.

0
source

Disclaimer: I did not create this solution, but it is clean and elegant, and I thought it should be included here:

(Adapted from Search and replace field codes in Word ):

  • Create or find one instance of the field in which you want to convert text to
  • Visible Field Codes ( Alt F9 )
  • Copy the code for the field you want to use on the clipboard (select and Ctrl C )
  • Open the Replace dialog box ( Ctrl H ), paste the text you want to replace in the Find what field, and then type ^c in Replace with .

This will replace your text with the contents of the clipboard, turning it into the code of the field that you copied in step 3. It also copies formatting information (font, color, etc.) to control how the field appears when it is hidden (Caution : I tested it only in Word 2003 only under Windows 7.)

0
source

All Articles