View Single Post
 
Old 08-15-2014, 03:27 AM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,374
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 code in the link does work as it should - just not as you want it to. For your purposes, you could use something based on:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Rng As Range
Set Rng = ActiveDocument.GoTo(What:=wdGoToPage, Name:=3)
Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\page")
With Rng
  With .Duplicate
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = "in"
      .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 = True
      If .InRange(Rng) = True Then
        .Text = "on"
        .Collapse wdCollapseEnd
        .Find.Execute
      Else: Exit Do
      End If
    Loop
  End With
End With
Application.ScreenUpdating = False
End Sub
or:
Code:
Sub Demo()
Application.ScreenUpdating = True
Dim Rng As Range
Set Rng = ActiveDocument.GoTo(What:=wdGoToPage, Name:=3)
Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\page")
With Rng.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Text = "in"
  .Replacement.Text = "on"
  .Forward = True
  .Wrap = wdFindStop
  .Format = False
  .MatchCase = False
  .MatchWholeWord = False
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
  .Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]

Last edited by macropod; 08-15-2014 at 03:29 AM. Reason: Alernate code
Reply With Quote