Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

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

combobox

  • Please log in to reply
No replies to this topic

#1 Anavrin

Anavrin

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 28 January 2012 - 01:50 PM

*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 ** As String
        ** = genderBox.Text
        If ** = "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*

  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download