Posted on 2009-04-18
Last Modified: 2016-10-02
Code attached gives me 3x a msgbox .. {TEST1 HALLO} {TEST2 REALLY} and {TEST3 NIGHT} .. i see in the word document that the correct text is selected .. what i want to do now is to replace all 3 {TEST?} with the second word between the { }

so original word document: {TEST1 HALLO} is changed to HALLO ... {TEST2 REALLY} is changed to REALLY etc



        With objWord.Selection.Find

            .Text = "\{TEST*\}"

            .Forward = True

            .Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue

            .Format = False

            .MatchCase = False

            .MatchWholeWord = False

            .MatchWildcards = True

            .MatchSoundsLike = False

            .MatchAllWordForms = False

        End With



        Do While True



            If objWord.Selection.Find.Found Then





                Exit Do

            End If


Open in new window

Question by:Amien90
    LVL 4

    Expert Comment

    Dim s as string
    Dim s2 as string

    s = objWord.Selection.Text
    s2 = s.substring(s.indexOf(" "), s.length - s.indexOf(" "))

    something like that should do what you want
    subString returns a string substring(startposition, numberofcharacters)
    indexOf returns the first occurance of a character in a string so we look for the first space
    and get the substring from here until the length minus the number of characters in we started

    hope this helps

    Author Comment

    the problem is not to extract HALLO and REALLY out of objWord.Selection.Text

    the problem is to make objWord.Selection.Find.Replacement.Text a flexibel text .. based on objWord.Selection.Text

    LVL 4

    Expert Comment

    I see you want to extract the text

    and then write it over the words in the words in the original word document?
    LVL 4

    Accepted Solution

    something like

    try extracting the bit you want
    and use something like

    .Replacement.Text = s2

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video discusses moving either the default database or any database to a new volume.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now