The string you passed as an argument to the Execute statement cannot be parsed as a statement. The Execute statement can be used to dynamically execute VBScript code. For example, consider the following VBScript code.

CopyCode imageCopy Code
Execute "msgbox 1"  'This works because msgbox is a statement.
Execute "5*4"       'This fails because 5*4 cannot be interpreted as a statement.

The Expected statement error is also generated during the compilation of any script code that expects a statement, not just by Execute and Eval. For example, the following code causes this error in Internet Explorer,

CopyCode imageCopy Code
<html>
<script language=vbscript>
    5*4
</script>
</html>

Notice that there are two distinct and unrelated Execute statements in VBScript,

  • the Execute statement that compiles and executes statements on the fly,

  • the Regular Expression Execute method.

To correct this error

  • Confirm that the string being passed to Execute is a statement.

  • If the string you want to evaluate is an expression, use Eval.

See Also