If-Then End-If Autocompletion


All If-Then statements must be followed by an End-If statement. VbaPrime automatically adds the trailing End-If statement, then places the cursor inside the If statement. This ensures that you can keep typing the code you want to write, resulting in a fluid programming style.


The following animation demonstrates the End If statement being added. The cursor is placed above the End If and indented by one tab.


Perform the following steps to see If-Then End-If completion:

  1. Open the Visual Basic Editor (VBE) and double-click on a module to open up its code window.
  2. Type Sub MySub() into the code window and then press enter. The VBE will automatically add the End Sub statement.
  3. Type If true Then, then press enter.
  4. VbaPrime will add the End If statement and place the cursor below the If true Then statement.

Note how VbaPrime's handling of If Then is very similar the Visual Basic Editor's handling of Sub MySub(). This is part of VbaPrime's strategy of augmenting the Visual Basic Editor.

Existing Code

When you press the enter key, VbaPrime will check to see if there is already an End If statement that corresponds to the If Then statement. If there is an End If, VbaPrime will not add any code. This feature prevents spurious End If statements being added as you navigate around existing code.