View Single Post
 
Old 08-29-2017, 10:11 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,521
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The only paragraphs that would be affected are those following a paragraph containing your 'trigger' text. Obviously, if you have multiple consecutive paragraphs containing that text, they'd all be capitalised.

For a large document with many items to process, it's beneficial to yield time to the operating system periodically. Accordingly, try:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim i As Long
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = InputBox("What is the Text to Find")
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
  End With
  Do While .Find.Found
    i = i + 1
    If i Mod 100 = 0 Then DoEvents
    .Paragraphs.Last.Next.Range.Font.AllCaps = True
    .Start = .Paragraphs.Last.Range.End
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
With this version, the OS gets some breathing space after every 100 updates. The revised code also avoids re-processing a paragraph if your 'trigger' occurs in it multiple times, which will improve efficiency in such cases.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote