Hi everyone! I am using Word 2003. I created a form that users enter information into. Then, a macro runs that replaces text in a document with information entered into the form. For instance, it will search for *aa* and replace with whatever the user typed into the form for text box aa.
It works great, except my problem is: If the user does not add any text, the searched item is replaced with nothing. I don't want that. How can I make the macro skip the current search and move on to the next search if nothing is entered into a text box? Can you please help me with a solution? THANK YOU.
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*aa*"
If tbAA.Text = "" Then
Resume Next
Else: .Replacement.Text = tbAA.Text
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "*A*"
.Replacement.Text = tba.Text
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "*bb*"
.Replacement.Text = tbBB.Text
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
It works great, except my problem is: If the user does not add any text, the searched item is replaced with nothing. I don't want that. How can I make the macro skip the current search and move on to the next search if nothing is entered into a text box? Can you please help me with a solution? THANK YOU.
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*aa*"
If tbAA.Text = "" Then
Resume Next
Else: .Replacement.Text = tbAA.Text
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "*A*"
.Replacement.Text = tba.Text
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "*bb*"
.Replacement.Text = tbBB.Text
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
End With
Selection.Find.Execute Replace:=wdReplaceAll