Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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

Posted on 2004-10-21
Medium Priority
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:Richard Kreidl
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 18

Expert Comment

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



Author Comment

by:Richard Kreidl
ID: 12373560
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

armoghan earned 1000 total points
ID: 12378130
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

ID: 12380198
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)

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Screencast - Getting to Know the Pipeline

610 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