Re: Apply a user-defined character style to all ocurrences of manual bold formatting but skipping some specific paragraphs



Hi Andreas,

what about the idea, that the command
range.font.reset
reveals, whether there was formatting manually applied?

Something along these lines, maybe:

Sub Macro7()
Dim rDcm As Range
Set rDcm = ActiveDocument.StoryRanges(wdMainTextStory)
With rDcm.Find
.Font.Bold = True
While .Execute
rDcm.Font.Reset
' rDcm.Select ' for testing
If rDcm.Font.Bold = False Then
rDcm.Style = "BoldStyle"
End If
' rDcm.Select ' for testing
rDcm.start = rDcm.End
rDcm.End = ActiveDocument.StoryRanges(wdMainTextStory).End
Wend
End With
End Sub

If you create a new range, by
Set rDcm = ActiveDocument.StoryRanges(wdMainTextStory)
it is not necessary to care about find.options like
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindContinue
etc.

All options are set to their default values.
However, I don't know, what they are. ;-)

Also
activedocument.range seems to be equivalent to
ActiveDocument.StoryRanges(wdMainTextStory).

But I'm not sure about that either.

Whithout covering all possible complications, of course,

cheers

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
.



Relevant Pages

  • Re: Make Word macro find text in footnotes, headers, etc?
    ... top of the private sub) to this position (I've shown the surrounding lines ... >> For Each rDcm In ActiveDocument.StoryRanges ... >> The private sub CharacterByCharacterSearch IS in the same module, ... > Dim rDcm As Range ...
    (microsoft.public.word.vba.general)
  • Re: For Review
    ... issue being limited to the story and the macro referenced by Doug Robbins. ... > Sub Test3() ... > For Each rDcm In ActiveDocument.StoryRanges ... > Private Sub HighlightText(rLoc As Range, sWrd As String, ...
    (microsoft.public.word.vba.general)
  • Re: For Review
    ... and go ahead and tear it apart. ... Sub Test3() ... For Each rDcm In ActiveDocument.StoryRanges ... Private Sub HighlightText(rLoc As Range, sWrd As String, ...
    (microsoft.public.word.vba.general)
  • Re: Wörter im WORD Dokument mit c# suchen.
    ... >ich verwende Word Interop in meinem c# project. ... >Sub FindWord() ... >Dim rDcm As Range ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: Make Word macro find text in footnotes, headers, etc?
    ... The private sub CharacterByCharacterSearch IS in the same module, ... > Dim oChr As Object ... > For Each rDcm In ActiveDocument.StoryRanges ... > ' for determining font name when adding changes ...
    (microsoft.public.word.vba.general)