Jump to content

Using "If" statement with combobox to find and replace text in a word document

- - - - -

  • Please log in to reply
No replies to this topic

#1
Anavrin

Anavrin

    Newbie

  • Members
  • Pip
  • 4 posts
*Please disregard. I found the problem. I'm sure I'll need more help later so don't count this one against me! :)*


I'm working on the project I mentioned in my introduction http://forum.codecal...ello-world.html

Using Visual Basic 6 and I'm a total newb so keep that in mind. Here is the code I'm having trouble with.

        Dim sex As String

        sex = genderBox.Text

        If sex = "Female" Then

            oWord.Selection.Find.Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)

            With oWord.Selection.Find

                .Text = "he"

                .Replacement.Text = "she"

                .Forward = True

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

                .Format = False

                .MatchCase = False

                .MatchWholeWord = True

                .MatchWildcards = False

                .MatchSoundsLike = False

                .MatchAllWordForms = False

            End With

            oWord.Selection.Find.Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)

            With oWord.Selection.Find

                .Text = "male"

                .Replacement.Text = "female"

                .Forward = True

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

                .Format = False

                .MatchCase = False

                .MatchWholeWord = True

                .MatchWildcards = False

                .MatchSoundsLike = False

                .MatchAllWordForms = False

            End With

            oWord.Selection.Find.Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll) *was missing this line

        End If

The first instance of find and replace is working fine (it replaces all instances of "he" with "she" in the document). However, the following instances are not working ("male" is not replaced with "female" in the document). If you can help me out I would really appreciate it. Thank you for your time.

Edited by Anavrin, 29 January 2012 - 01:32 AM.
Found the problem *Sorry*





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users