Else / End If

 

The Else and End If commands are inserted directly into the script as there is not an edit window associated with them. From the Script Editor click on the Logic category of commands to expand the category. Then insert the Else or End If command into the script.

 

 

Else

The ELSE command is used in conjunction with a conditional statement. Everything after an ELSE command until an ENDIF command is reached will be executed if the conditional is FALSE.

 

 

End If

The ENDIF command is used to mark the place where macro control should stop after a conditional statement is encountered.

 

Example

Below is a small example of how to use the If statements. For this example we selected the If Clipboard Text Equals command.

 

If the text saved to the clipboard is "Macro Express" then the macro will open the www.macros.com home page. The Else command separates the If statement. If something other than "Macro Express" is saved to the clipboard, the web site command is skipped. Instead, the macro activates the Notepad window and enters "This is a test".

 

 

Sample Macro

 

If Clipboard Equals "Macro Express"

  Web Site, "https://www.macros.com", using Default Web Browser

Else

  Window Activate: Notepad

  Wait for Window Title: Notepad

  Text Type (Simulate Keystrokes): This is a test.

End If

---- continue with remainder of macro commands ---

 

 

This is essentially the format used for any of the If statements when wanting to take two different actions based on the result of the If statement.

 

If two different actions are not needed, remove the Else statement as shown below. In this case, if the clipboard contents equal Macro Express, the macro opens the www.macros.com web page. If the clipboard contents are different, then the web site command is skipped. The End If command signifies that the If statement is finished and the macro continues with the rest of the commands.

 

 

Sample Macro

 

If Clipboard Equals "Macro Express"

  Web Site, "https://www.macros.com", using Default Web Browser

End If

---- continue with remainder of macro commands ---

 

 

Look at the AND/OR/XOR and Using IF Statements topics to see other examples using the If statements.