Solved

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

Posted on 2014-12-13
2
200 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 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

There is a feature provided by MS Word that lets you create an Table of Contents for your Word document automatically. To use this feature for other documents there are two steps involved,   1.  Prepare your document for a table of contents (he…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

756 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