简体   繁体   English

VBA Word-查找和替换

[英]VBA Word - Find And Replace

I'm trying to create a VBA Macro in Word that will search for some text and apply a specific style to it. 我正在尝试在Word中创建VBA宏,该宏将搜索一些文本并对其应用特定的样式。 Before I automate it I'm trying to do it manually via the Find and Replace tool. 在自动化之前,我尝试通过“查找和替换”工具手动进行操作。 Here's what I'm doing... 这就是我在做什么...

  1. Open a word document with the text: This is the first sentence in the word document. 用文字打开一个单词文档:这是单词文档中的第一句话。
  2. Make the phrase "in the" to be bold. 将短语“中”设为粗体。
  3. Open up the Find and Replace Tool via Edit --> Replace. 通过编辑->替换打开查找和替换工具。
  4. In the "Find what:" field only have Format: Font:Bold 在“查找内容:”字段中仅具有格式:字体:粗体
  5. In the "Replace with:" field only have Format: Style:Heading 1 在“替换为:”字段中,只有格式:样式:标题1
  6. Click on "Replace All" 点击“全部替换”

Notice how the entire sentence has been changed to "Heading 1". 注意整个句子如何更改为“标题1”。 I only wanted the areas in the document that were "bold" to be in "Heading 1" not the whole sentence. 我只希望文档中“加粗”的区域位于“标题1”中,而不是整个句子。

What am I doing wrong? 我究竟做错了什么?

A Heading is a heading. 标题是一个标题。

If you change any part of the sentence to Heading1 the whole sentence becomes the heading. 如果将句子的任何部分更改为Heading1,则整个句子将成为标题。 If you want it to be bigger, my suggestion would be to increase the font size not make it a Heading! 如果您希望它更大,我的建议是增加字体大小,而不要使其成为标题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM