Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. find and replace (simple VBA)

find and replace (simple VBA)

Scheduled Pinned Locked Moved Visual Basic
questionhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hello all -- i have a problem that is really getting me down . . . I am selecting a line in MS Word and trying to remove all double spaces " " and replace them with single spaces -- until I only have single spaces. i.e. " hello world" => " hello world" I created a _very_ short macro that loops until the selection returns a 'false' value. Do Loop Until Selection.Find.Execute(Replace:=wdReplaceOne, ReplaceWith:=" ", FindText:=" ") After debugging for a while I found that what is happening is that the selection is changing each time -- I tried the following to correct this: Dim blnEnd As Boolean With Selection Do blnEnd = .Find.Execute(FindText:=" ", ReplaceWith:=" ", Replace:=wdReplaceOne) Loop While blnEnd = True End With but my selection keeps changing just like before -- how do I iterate through a selection that does not change? please help -- this is a killin' me :confused: tim --------------------------------------- Tim Booher

    V 1 Reply Last reply
    0
    • L Lost User

      Hello all -- i have a problem that is really getting me down . . . I am selecting a line in MS Word and trying to remove all double spaces " " and replace them with single spaces -- until I only have single spaces. i.e. " hello world" => " hello world" I created a _very_ short macro that loops until the selection returns a 'false' value. Do Loop Until Selection.Find.Execute(Replace:=wdReplaceOne, ReplaceWith:=" ", FindText:=" ") After debugging for a while I found that what is happening is that the selection is changing each time -- I tried the following to correct this: Dim blnEnd As Boolean With Selection Do blnEnd = .Find.Execute(FindText:=" ", ReplaceWith:=" ", Replace:=wdReplaceOne) Loop While blnEnd = True End With but my selection keeps changing just like before -- how do I iterate through a selection that does not change? please help -- this is a killin' me :confused: tim --------------------------------------- Tim Booher

      V Offline
      V Offline
      Volodya Orlenko
      wrote on last edited by
      #2

      Here's a script that works: Sub Macro8() Dim fContinue As Boolean fContinue = True Dim Sel As Range Do While fContinue Set Sel = Selection.Range Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = " " .Replacement.Text = " " .Forward = True .Wrap = wdFindAsk .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With fContinue = Selection.Find.Execute(Replace:=wdReplaceOne) Selection.Start = Sel.Start Selection.End = Sel.End Loop End Sub Volodya Orlenko, orlenko [at] hotmail [dot] com

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups