how to assign replacement text to string Variable?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • peroron2000
    New Member
    • Sep 2013
    • 3

    how to assign replacement text to string Variable?

    In the following example I am doing a find and replace using a macro inside Word. At the bottom you can see that I assign the searched for text to the variable sText. How would I assign the replacement.tex t to a variable? So for example in this case the macro finds "To:" and replaces it with o. I would like to be able to assign "o" to a variable


    Code:
    Sub Macro6()
    '
    ' Macro6 Macro
    '
    '
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "T(o):"
            .Replacement.Text = "\1"
            .MatchWildcards = True
        End With
        Selection.Find.Execute
        With Selection
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseStart
            Else
                .Collapse Direction:=wdCollapseEnd
            End If
            .Find.Execute Replace:=wdReplaceOne
            If .Find.Forward = True Then
                .Collapse Direction:=wdCollapseEnd
            Else
                .Collapse Direction:=wdCollapseStart
            End If
            .Find.Execute
        End With
        sText = Application.Selection.Text
    End Sub
Working...