How to open a word document and search for specfic text?

Posted on 2004-10-21
Last Modified: 2010-08-05
I know how this works in Word VBA, but I'm not sure how to do it in VB .Net. Are Word VBA macro keywords and synatx portable to VB .Net? Basically, I have 20 to 30 page word document that I want to search for specfic text that a user would supply on a form using a text box and commandbutton.
Question by:rkckjk
    LVL 18

    Expert Comment

    Check out this Article related to Search for Text in Word Document on MSDN:

    LVL 2

    Author Comment

    I saw that article, isn't that for VB 6.0? And don't you have to open and read a word document before you can search it?
    LVL 18

    Accepted Solution

    You need to add the Com reference of MS Word
    see the following article for it

    and then when you have the Active Document Object you can search it even without displaying it.

    The link mentioned by tusharashah will work for VB.NET as well. see other related links at the bottom
    also see
    LVL 28

    Expert Comment

    This will find and replace  a string

    Dim bFound As Boolean

        With Selection.Find
            .Text = "s"
            .Replacement.Text = "b"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
       bFound = Selection.Find.Execute(, , , , , , , , , , 2)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    The Complete Ruby on Rails Developer Course

    Ruby on Rails is one of the most popular web development frameworks, and a useful tool used by both startups and more established companies to build strong graphic user interfaces, and responsive websites and apps.

    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    In this Experts Exchange video Micro Tutorial, I'm going to show how small business owners who use Google Apps can save money by setting up what is called a catch-all email address in their Gmail accounts. By using the catch-all feature, small busin…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

    934 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

    13 Experts available now in Live!

    Get 1:1 Help Now