none
Replace String RRS feed

  • Question

  • Dear All,

    Its that possible to show input box in word and user insert data in that box.

    after that All string will replace. Maybe like Find And Replace but string that replace is Constanta,

    i want user only input the data and word automatically replace it from whole document.

    How that i can solve that?

    Please Help

    Best regards,

    Surbakti

    Thursday, December 4, 2014 9:42 AM

Answers

  • Try this macro:

    Sub ReplaceIt()
        Const strReplace = "Constanta"
        Dim strFind As String
        strFind = InputBox("Enter text to replace with " & strReplace)
        If strFind = "" Then
            MsgBox "No text specified!", vbExclamation
            Exit Sub
        End If
        Application.ScreenUpdating = False
        With ActiveDocument.Content.Find
            .ClearFormatting
            .Text = strFind
            .Replacement.ClearFormatting
            .Replacement.Text = strReplace
            .MatchCase = False ' or True if you want case-sensitive search
            .MatchWholeWord = True ' or False if you want to replace partial words
            .MatchWildcards = False
            .Execute Replace:=wdReplaceAll
        End With
        Application.ScreenUpdating = True
    End Sub


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Thursday, December 4, 2014 4:08 PM