+ Reply to Thread
Results 1 to 2 of 2

Finding and selecting text in word from excel

  1. #1
    akh2103@gmail.com
    Guest

    Finding and selecting text in word from excel

    Hello--I have written a simple macro trying to find and select certain
    text in a word document (it is part of a larger project). When the
    macro is finished running, I would like word to have the first instance
    of the text selected. However, the following code is not doing the job.
    I am sure I am missing something simple. Can anyone help?
    -Abe

    Sub find()

    Set wdapp = GetObject(, "Word.Application")
    Set wddoc = wdapp.ActiveDocument

    With wddoc.Content.find
    .Text = "Q1"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchAllWordForms = False
    .Execute (findtext = "Q1")
    End With

    End Sub


  2. #2
    akh2103@gmail.com
    Guest

    Re: Finding and selecting text in word from excel

    This one is actually embarrassingly simple. I am missing the statement
    Selection.Find.Execute at the end of the find code. I guess the find
    property needs an additional step to be completed. The working code
    goes:


    Set wdapp = GetObject(, "Word.Application")
    > Set wddoc = wdapp.ActiveDocument
    >
    > With wddoc.Content.find
    > .Text = "Q1"
    > .Replacement.Text = ""
    > .Forward = True
    > .Wrap = wdFindContinue
    > .Format = True
    > .MatchCase = False
    > .MatchWholeWord = False
    > .MatchWildcards = False
    > .MatchAllWordForms = False
    > .Execute (findtext = "Q1")
    > End With

    selection.find.execute
    > End Sub


    akh2...@gmail.com wrote:
    > Hello--I have written a simple macro trying to find and select certain
    > text in a word document (it is part of a larger project). When the
    > macro is finished running, I would like word to have the first instance
    > of the text selected. However, the following code is not doing the job.
    > I am sure I am missing something simple. Can anyone help?
    > -Abe
    >
    > Sub find()
    >
    >



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1