Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-15-2014, 03:27 AM
macropod's Avatar
macropod macropod is offline Search and Replace vba Word 2003 Windows 7 32bit Search and Replace vba Word 2003 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,375
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
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search and Replace vba Word 2003 search and replace dirkoo Word VBA 2 08-14-2013 11:25 AM
Search and Replace vba Word 2003 Odd search and replace query Rabski Word 1 11-13-2012 02:25 PM
Search and Replace vba Word 2003 WORD: Rtf and search-replace (regexp/fonts) seteshpl Word 1 09-06-2011 01:35 AM
Search Replace Copy dblack7211 Word 0 05-05-2010 01:19 PM
Search and Replace - Clear Search box JostClan Word 1 05-04-2010 08:46 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:51 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft