Consulting

Results 1 to 2 of 2

Thread: IF - Then statement

  1. #1
    VBAX Regular
    Joined
    Aug 2017
    Posts
    10
    Location

    IF - Then statement

    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.

  2. #2
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,273
    Location
    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
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •