0

I am trying to automate a .application file to open automatically on an end users machine. The code I found online says to do this:

Dim my_file

my_file = "c:/location/example.application"

ShellExecute 0, vbNullString, my_file, vbNullString, vbNullString, vbNormalFocus

but when I try to run it I get a type mismatch error on line 4 which is the ShellExecute line. How can I fix this?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
JMQRSQ
  • 1
  • 1

1 Answers1

3

ShellExecute() is a method of a Shell Application object. You'll need to create an instance of the class before you can call one of its methods:

Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute my_file

Most of the parameters to ShellExecute() are optional and can be omitted, if you'd like.

See this page for information.

Also note that constants defined by external type libraries (as is the case here) are not immediately available to VBScript. That means your script will not understand vbNormalFocus. The easiest way to overcome this is to just define the constants yourself.

Const vbNormalFocus = 1
Bond
  • 16,071
  • 6
  • 30
  • 53