1
votes
  • I would like to select a piece of text in MS Word 2010 document.
  • Then using a macro: select the unbolded text & change the colour of that text to blue

NB: I don't want to do this to the whole of the document text, just to the paragraph/block of text I have selected)

Picture demonstrating what I would like to do:

pic

I have tried creating the following macro - but it for some reason makes all of the text (bolded and unbolded) blue

    Sub MakeUnboldedTextBlue()
'
' MakeUnboldedTextBlue Macro
'
'
    Selection.Find.ClearFormatting
    Selection.Find.Font.Bold = False
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindAsk
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchKashida = False
        .MatchDiacritics = False
        .MatchAlefHamza = False
        .MatchControl = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Font.Color = 15773696
End Sub

Update: I would also like to exclude the bullet symbols from 'cyanizisation' (if possible)

For example: Example of the bullet symbols not being cyanized

1

1 Answers

0
votes

You look through every character in the selected text, then colour it if it isn't bold:

Option Explicit

Sub CyanizeNonBoldInSelection()
    Dim oRange As range
    Dim oChar As range
    Dim oListFormat As ListFormat

    Application.UndoRecord.StartCustomRecord "CyanizeNonBoldInSelection"

    Set oRange = Selection.range

    For Each oChar In oRange.Characters

        If oChar.Bold = False Then

            oChar.Font.ColorIndex = wdTurquoise

            If oChar.ListParagraphs.Count > 0 Then
                Set oListFormat = oChar.ListParagraphs(1).range.ListFormat
                oListFormat.ListTemplate.ListLevels(oListFormat.ListLevelNumber).Font.ColorIndex = wdTurquoise
            End If

        End If
    Next oChar

    Application.UndoRecord.EndCustomRecord

End Sub