PDA

View Full Version : [SOLVED:] Delete Text Between 2 Ranges - Input Box



dj44
03-18-2017, 06:56 PM
Evening folks,:)

I made an input box to delete text between 2 ranges but its fallen flat and fails to start up ?




Sub DeleteBetween2Ranges()


Dim myRange As Range

Dim oText1 As String
Dim oText2 As String

oText1 = InputBox("Enter First Word :")
If Len(oText) = 0 Then
Exit Sub
End If


oText2 = InputBox("Enter Second Word :")
If Len(oText) = 0 Then
Exit Sub
End If

If Len(oText) = 0 Then
Exit Sub
End If



Set myRange = ActiveDocument.Range
With myRange.Find


Do While .Execute(FindText:="oText1*oText2", MatchWildcards:=True)


myRange.Text = ""

myRange.Collapse
Loop
End With

End Sub



I would like my input box as I have to always change the delete between the 2 ids

Any ideas welcome

mana
03-18-2017, 07:21 PM
>"oText1*oText2"

oText1 & "*" & oText2

mana
03-18-2017, 07:30 PM
>If Len(oText) = 0 Then


If Len(oText1) = 0 Then
and
If Len(oText2) = 0 Then

dj44
03-18-2017, 08:04 PM
As Usual,
I spent ages looking for this bug - that i couldnt see
If Len(oText) = 0 Then
Exit Sub
End If

I forgot to put the oText1 in brackets

Also this did the trickk
oText1 & "*" & oText2

thank you Mana

and all have great evening :yes