Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Word macro search & replace text only if original text is bold

Posted on 2014-12-13
2
Medium Priority
?
208 Views
Last Modified: 2014-12-13
I have a document which has comments in bold on some lines, and I need to change the bold text to other text, and retain the bold styling.

I know how to find and replace text in a macro, but not how to determine whether the text is bold so that only the bold text is changed.

Any ideas?
0
Comment
Question by:jdthedj
2 Comments
 
LVL 18

Accepted Solution

by:
Simon earned 2000 total points
ID: 40498388
It's  the Format:=True of the .Find.Execute method that you need
See the MSDN reference for the FIND method.
This other MSDN link has examples with formatting
The final example is very close to what you need to do....
With ActiveDocument.Content.Find
    .ClearFormatting
    .Font.Bold = True
    With .Replacement
        .ClearFormatting
        .Font.Bold = TRUE
    End With
    .Execute FindText:="Comment", ReplaceWith:="ReplacementComment", _
        Format:=True, Replace:=wdReplaceAll
End With

Open in new window

0
 
LVL 3

Author Closing Comment

by:jdthedj
ID: 40498471
Thanks very much Simon - exactly what I need, and a very full answer.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question