简体   繁体   中英

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. 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
  6. Click on "Replace All"

Notice how the entire sentence has been changed to "Heading 1". I only wanted the areas in the document that were "bold" to be in "Heading 1" not the whole sentence.

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. If you want it to be bigger, my suggestion would be to increase the font size not make it a Heading!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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