Jump to content


Check out our Community Blogs

Anavrin

Member Since 14 Jan 2012
Offline Last Active Feb 13 2012 02:37 PM
-----

Topics I've Started

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

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.

Hello World :)

14 January 2012 - 10:14 AM

Thank you for taking the time to greet new members. I need to write, what I think will be a simple program, but I'm having trouble finding out what software to use or how to get started. My wife does interviews for her job, which essentially follow the same format. I would like to make a program where she can enter the answers to her interview questions and have the answers be inserted into a nicely formatted word document template. Currently she has a word document template and has to change a lot of details using "replace" or just highlighted and changing things. My daughter just started daycare so I have a few hours twice a week to work on this project. If anyone could help point me in the right direction I would really appreciate it. Thank you.

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