PDA

View Full Version : IF - Then statement



asad
10-09-2017, 03:55 AM
Hi guys,
First, I would like to tell you that this example is not for English but for Arabic
This code I want to do the following:
- Search once at each hotkey press
- If the word is finished with a letter M delete the letter and write instead letter N.
- If the word ends with a letter N, delete the letter and write instead a letter M.
I do not know well using the IF - Then statement
Please help me



Sub findend()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "[nm]>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
Selection.Find.Execute
With Selection
If Selection.Find.Found = n Then
Selection.TypeText Text:=m
Else
If Selection.Find.Found = m Then
Selection.TypeText Text:=n


End If
End Sub




Any help would be greatly appreciated.

macropod
10-09-2017, 01:50 PM
Sub findend()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "[nm]>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
.Execute
End With
If Selection.Find.Found = True Then
Selection.Text = Chr(109.5 - ((Asc(Selection.Text) = 109) + 1) / 2)
End If
End Sub