Re: Replacing text via code



Roger.

Something like:

Sub ScratchMacro()

Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.MatchWildcards = True
.Text = "([0-9])-([0-9])"
.Replacement.Text = "\1^=\2"
.Execute Replace:=wdReplaceAll
End With
End Sub

.



Relevant Pages

  • Re: Scope of Selection.Find.Format, Macro Search&Replace
    ... Sub ScratchMacro() ... Dim oRng As Word.Range ... .Execute Replace:=wdReplaceAll ... Prev by Date: ...
    (microsoft.public.word.vba.general)
  • Re: Spaces after Periods
    ... Sub TwoSpacesAfterSentence() ... Dim oRng As Range ... .Execute Replace:=wdReplaceAll ... after sentence punctuation, even before Bill Gates got a job). ...
    (microsoft.public.word.docmanagement)
  • Re: Bold every second line
    ... "macropod" wrote: ... Dim oRng As Range ... .Execute Replace:=wdReplaceAll ... I need a macro because new entries will be inserted at various ...
    (microsoft.public.word.vba.general)
  • Re: Bold every second line
    ... Dim oRng As Range ... .MatchWholeWord = False ... .Execute Replace:=wdReplaceAll ... I need a macro because new entries will be inserted at various points and so muck up any original formatting. ...
    (microsoft.public.word.vba.general)
  • Re: find capitalized words and replace with a text
    ... Sub ScratchMacro() ... Dim oRng As Word.Range ... .MatchWildcards = True ... .Execute Replace:=wdReplaceAll ...
    (microsoft.public.word.newusers)

Loading