title: VBA IF ElseIF Else
body: <p>Having a problem with If, ElseIf, Else function in VBA. </p>
  
  <p>My code needs to look for "Text1", elseIf needs to look for "Text2", else make a note in a log file. </p>
  
  <p>The problem is I can't seem to change the Find parameters as part of the ElseIF..</p>
  
  <pre><code>ElseIf Selection.Find.ClearFormatting    
  With Selection.Find
    .Forward = False
    .Text = "Text2"
  End With                                            
  Selection.Find.Execute Then
  </code></pre>
  
  <p>The ElseIF will only work if I put it infront of The execute line, this means im still searching "Text1" that doesn't exist.</p>
  
  <pre><code>ElseIf Selection.Find.Execute Then
  </code></pre>
  
  <p>Any idea where im going wrong?</p>
  
  <p>Full code:</p>
  
  <pre><code>Sub Testing()
  
      Dim LogFile As String
  
      LogFile = "G:\ErrorLog.txt"
  
      Selection.Find.ClearFormatting
      With Selection.Find
          .Forward = False
          .Text = "Text1"
      End With
  
      If Selection.Find.Execute Then
  
          MsgBox "Found Text1"
  
          Selection.Find.ClearFormatting
          With Selection.Find
              .Forward = False
              .Text = "Text2"
          End With
  
      ElseIf Selection.Find.Execute Then
  
           MsgBox "Found Text2"
  
      Else
  
          Open LogFile For Append As #1
          Print #1, Now &amp; " " &amp; "Text Field Error" &amp; ": "
          Close #1
  
      End If
  
  End Sub
  </code></pre>