Results 1 to 4 of 4

Thread: Solved: mySelection.Find.Execute

  1. #1

    Solved: mySelection.Find.Execute

    I am working with a program to change text with the function

    mySelection.Find.Execute

    but I would like to get the result of the function in numbers. Like the word interface does, giving the number of instances replaced trhoughout the document.

    Do I need to use a differente function or I am missing something?

    Thanks in advance for your help and comments

    Joey


    Never mind guys. I was thinking inside the box. I need to run a cycle before with a counter only to FIND the occurrences and then run the replace option.

    Thanks anyway

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi,

    Welcome to VBAX!

    Glad to see you've made it work. Can you post you're code for others to benifit from it?
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  3. #3
    This is the code:

    [VBA]
    mySelection = Worddoc.Range

    bFound =
    True

    DoWhile bFound = True

    bFound = mySelection.Find.Execute(txtFind.Text)

    If bFound = TrueThen

    iCounter = iCounter + 1

    EndIf

    Loop

    mySelection = Worddoc.Range

    bFound =
    True

    bFound = mySelection.Find.Execute(txtFind.Text, , True, , , , False, , , txtReplace.Text, Word.WdReplace.wdReplaceAll, , , , )

    bFound =
    True

    DoWhile bFound = True

    bFound = mySelection.Find.Execute(txtReplace.Text)

    If bFound = TrueThen

    mySelection.HighlightColorIndex = Word.WdColorIndex.wdYellow

    EndIf

    Loop

    MsgBox("The text was found " & iCounter & " times")

    [/VBA]

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi,

    Thnxx for posting back!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

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