[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 135
  • Last Modified:

Adding exe file

How can i execute a exe file from a buttom.
1 Solution
chiche115Author Commented:
Please help me.
Shell + F1
I think caraf_g was trying to get you to look up the help page on "Shell"...

In the click event of your button put this code:

   Shell "whatever.exe",vbNormalFocus

and the program will run with normal focus...


Here's a function you can use to start a .exe file..

You can use it with code like..

  Call Run(exefilename)

Add this to the (declaration) part..

  Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

And here's the function code..

  Function Run(strFilePath As String, Optional strParms As String, Optional strDir As String) As String
    Const SW_SHOW = 5
    'Run the Program and Evaluate errors
    Select Case ShellExecute(0, "Open", strFilePath, strParms, strDir, SW_SHOW)
    Case 0
      Run = "Insufficent system memory or corrupt program file"
    Case 2
      Run = "File not found"
    Case 3
      Run = "Invalid path"
    Case 5
      Run = "Sharing or Protection Error"
    Case 6
      Run = "Seperate data segments are required for each task"
    Case 8
      Run = "Insufficient memory to run the program"
    Case 10
      Run = "Incorrect Windows version"
    Case 11
      Run = "Invalid program file"
    Case 12
      Run = "Program file requires a different operating system"
    Case 13
      Run = "Program requires MS-DOS 4.0"
    Case 14
      Run = "Unknown program file type"
    Case 15
      Run = "Windows program does not support protected memory mode"
    Case 16
      Run = "Invalid use of data segments when loading a second instance of a program"
    Case 19
      Run = "Attempt to run a compressed program file"
    Case 20
      Run = "Invalid dynamic link library"
    Case 21
      Run = "Program requires Windows 32-bit extensions"
    Case Else
      Run = ""
    End Select

  End Function


Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now