English 中文(简体)
如何在 Microsoft Word 中搜索和替换包含字段的字段?
原标题:How to do search and replace involving fields in Microsoft Word?

我有一个Word文档, 包含参考方块, 以“ [field]. [field] ” 的形式出现, 换句话说, 在两个字段之间有一段时期。 我想从全球范围用一个空间来替换它 。

Word 提供了用于查找字段的“d” 特殊字符, 但出于某种原因, 查询“ d. d” 找不到任何东西 。 但是, “. d” 确实找不到 。 现在问题来了, 但是-- 我用什么来指定替换文本以保留字段代码? 如果使用常规表达式, 我可以使用 1 这样的“ 查找什么表达式 ”, 但使用正则表达式 (“ 模糊卡”) 模式不允许 。

我想我可以写一个宏...

最佳回答

在寻找字段时,通常最好走宏观路线,因为,正如你说的,W或d使用的查找算法在字段方面不象你所希望的那样起作用。

但如果您知道字段包含的确切内容,您可以指定一个搜索模式,该模式可能有效(但无论通配符模式如何)。

例如,如果您想要查找数字数字字段配对,例如

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

(这通常与文件中每一处相同的字段相同)

如果您真的需要寻找以下信息:

{ STYLEREF 1 s }.<any field>

您可以确保显示和搜索字段代码

^d STYLEREF 1 s ^21.^d

^19 STYLEREF 1 s ^21.^19

If you need to be m或e precise, you can spell out the second field as well.

"^d" only w或ks f或 finding the field beginning, not the field end.

It s a shame that ^w wants to find at least 1 whitespace character because otherwise it would be m或e robust to look f或

^19^wSTYLEREF^w1^ws^w^21.^19

Perhaps someone else knows how to w或k around that without using wildcards?

问题回答

我想补充一下比巴迪亚问题的解决方案。

索引输入字段的示例; 我们希望更改拼错的名称 。

  • Make sure hidden formatting is displayed (toggle with SHIFT+CTRL+F8).
  • 确保未选择通配符选项。 要搜索字段, 请使用打开和关闭字段括号代码( 如 Bibadia 的建议, 空格可使用 w ) :

    ^19 XE "Deo, John" ^21
  • 替换 won t 识别字段括号字符, 但允许插入剪贴板内容 。 要做到这一点, 请在文本中插入正确的条目 。 CTRL+F9 插入字段和类型 :

    XE "Doe, John"
  • 选择上面的字段并复制

  • 使用使用

    ^c
    in the replace box
  • 全部点击替换全部

答 -答! 答! 答! 答! 答! 答! 答!

Torzaburo, I suggest that you do this using a macro. You can start by recording the macro, and later refining your processing steps within the macro.

首先打开隐藏字符, 浏览到 Home & gt; 段落 & gt; 以切换显示/ 隐藏段落符号。 同时, 选择全部并切换显示/ 隐藏段落符号( 右键单击并选择“ 切换字段代码 ” ) 的字段代码 。

在您打开的空单词文档之外再打开一个新的空白单词文档。 您以后会使用它。 开始宏记录, 并按您所说的使用“ id” (字段代码) 查找字段 。

当发现字段时,只复制括号 中的字段文字,而不是完整的字段引用。虽然宏仍在记录,但 ALT + TAB 将新空白文档粘贴到新空白文档中,并将字段代码作为纯文本粘贴。

在此点, 做必需的查找 & amp; 替换处理到字段代码。 突出显示已处理的字段代码、 复制、 ALT + TAB 返回原始文档, 并在 {} 括号之间粘贴 。

停止宏记录。 在宏 VBA 中添加任何进一步的自定义处理 。

全部选择并重新切换字段代码。更新字段代码。

您不需要宏。 只要使用 Alt+F9 来切换所有字段代码, 然后查找并替换您想要更改的内容。 一旦替换完成, 请再次使用 Alt+F9 来切换字段代码 。

免责声明:我并没有提出这个解决方案, 但是它既干净又优雅,

(摘自Search & amp;替换文字中的字段代码 ):

  1. Create or find a single instance of the field you want to convert text to
  2. Toggle Field Codes visible (AltF9)
  3. Copy the code for the field you want to use to the Clipboard (highlight and CtrlC)
  4. Open the Replace dialog box (CtrlH), insert the text you want to replace in the Find What box and then enter ^c in the Replace With box.

这将用剪贴板的内容替换您的文字, 将其转换为您在第三步中复制的字段代码 。 它还会复制格式信息( 字体、 颜色等), 以控制隐藏时字段会如何出现 。 (Caveat: 我用 Word 2003 测试过此选项, 仅以 Windows 7 模式 。)

来得太晚了,对贝丝来说,可能为时已晚,对贝丝来说,也许为时已晚。这也许不是贝丝所期待的。但对于任何感兴趣的人来说,这也许不是贝丝所期待的。

听起来贝丝可能在整个文档中 使用 INSTERCAPTION (即存在实地代码) 创建了标题。 这意味着这些标题会( 自动) 以 CapTION 风格创建 。

将这些标题中的分隔符“.”改为“(空间)”,采取两个步骤:

[1] 转到References INSTER Capitation ,然后点击 NUBOING , 将 Separator 改为“EM-DASH”。 这将取代 Capittion 窗口中选定标签标题中的所有分隔符。 如果您在文档中使用其他标签( 如 FIGURE), 请逐一选择其他标签并重复此进程 。

[2] 在样式 Caption 中查找/替换搜索特殊字符“ em- dash” (), 替换为“ 。 点击 < code> REPLACE All

看呐!

NoTE: this 假设 em- dash 不出现在标题文本的任何地方。 如果它出现, 那么您需要做一个“ 中继” 之前和之后的“ 中继 ”, 以确保这些 em- dashes 不被上面的全局替换所触动 。

“ 中世纪前 ” 是指用其他字符串( 例如“ EM- DASH ” ) 替换在任何标题文本中从未出现过的 em- dash (“ ” ) 。 然后您将上述分隔符更改。 最后, “ 中世纪后 ” 将恢复标题中的 em- dashes, 将“ EM- DASH” 字符串用 em- dash 字符“ ” 进行全球替换 。





相关问题
WORD 2007 w/VBA

I have a question regarding a WORD 2007 form used to gather information from users. I had it working in WORD 2003 then pulled it over into WORD 2007 and got it working but couldn t leave well enough ...

Word opens extra blank document

I have an issue on a client machine that seems to be interferring with a word addin that ive built. When any word document opens on the client machine, a second blank document opens also. Ive seen ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Creating & Editing MS-Word documents on a linux server?

Looking to develop server-side application that will process documents. The source documents are mostly MS-Word 2003, 2007, i.e. the MS version of Docx. Want the server application to be able to run ...

Word document printed on MS Access report using OLE object

For years, we have been printing Word 2003 documents that have been saved to a OLE object column using an access report. We are using Access 2003. For some reason when we copy a Word 2003 document ...