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

Find and replace

Scheduled Pinned Locked Moved Visual Basic
toolsregexhelpquestion
1 Posts 1 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.
  • H Offline
    H Offline
    Harold_Wishes
    wrote on last edited by
    #1

    Hello, This is partly an MS-Word question but I am using VB subroutines which is where my problem arises. I have created a find and replace script that uses wildcards to find a pattern throughout a Microsoft Word 2003 document and replace the pattern with itself but with a different font color. The find and replace portions both work great as I am recording the macro (finding all instances of the pattern and changing the color). However, when I go back and run the macro to test it, it only finds the first instance of my pattern. Word apparently does not have the ability to record finds for all instances of a pattern in one pass. I tried putting a EOF or LOF function to force the macro to run until the end of file is reached but I get caught in an endless loop and I have to shut down the application all together. Does anyone know of a way of performing this action. Below is my code without a loop where only the first instance of the pattern is found. Thanks

    Sub test()
    '
    ' test Macro
    ' Macro recorded 8/5/2006 by Harold Woodall
    '
    Selection.Find.ClearFormatting
    For Counter = 1 To 500
    With Selection.Find
    .Text = "(\>[A-Z,a-z]{1,250}\<)"
    .Replacement.Text = "\1"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    End With
    Selection.Find.Execute
    With Selection.Font
    .Name = "Times New Roman"
    .Size = 12
    .Bold = True
    .Italic = False
    .Underline = wdUnderlineNone
    .UnderlineColor = wdColorAutomatic
    .StrikeThrough = False
    .DoubleStrikeThrough = False
    .Outline = False
    .Emboss = False
    .Shadow = False
    .Hidden = False
    .SmallCaps = False
    .AllCaps = False
    .Color = wdColorBlue
    .Engrave = False
    .Superscript = False
    .Subscript = False
    .Spacing = 0
    .Scaling = 100
    .Position = 0
    .Kerning = 0
    .Animation = wdAnimationNone
    End With
    Next
    End Sub

    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