Astra

Excel VBA Run External Program

Estimated reading: 2 minutes

In this article, you will learn various methods to run an external program from excel by using VBA 

Method 01: Run External Program by Using Shell Function

You can run any external program using the shell function in Excel VBA. 

The syntax of the shell function 

Excel VBA Run External Program

Where PathName(string) is the path of the program to be opened or run.

And the second parameter is the optional parameter, which indicates window style.

To know more about Shell function you can spend some time on the Microsoft Excel Documentation

Let’s jump to our main topic.

You can run any external program from Excel by using the following VBA code

Sub Run_External_Program1()
    ' Run the command
        VBA.shell "POWERPNT"
End Sub

Result:  After running the code by pressing F5, the PowerPoint app will open.

Excel VBA Run External Program

Note: 

  1. If you pass the wrong name of the program the VBA code will return a runtime error.
  2. Please check the following references before running the code
Excel VBA Run External Program2

Following VBA codes will give the same output

Code 1: You can get the same output by inserting the program path instead of the program name  

Sub Run_External_Program2()
    ' Replace the path and arguments with the ones for the program you want to run
    Dim Program_path As String
    Program_path = "C:\Program Files (x86)\Microsoft Office\root\Office16\POWERPNT.EXE"

    ' Run the command
    shell Program_path
End Sub

Code 2:  

Sub Run_External_Program3()
    ' Replace the path and arguments with the ones for the program you want to run
    Dim Program_path As String
    Program_path = Chr(34) & "C:\Program Files (x86)\Microsoft Office\root\Office16\POWERPNT.EXE" & Chr(34)
    ' Create a new instance of the WshShell object
    Dim shell As Object
    Set shell = CreateObject("WScript.Shell")

    ' Run the command
    shell.Run Program_path
End Sub

Method 02: Run External Program by CreateObject Method

You also can run an external program using the CreateObject method in Excel VBA

Sub Run_External_Program4()
    ' Create a new instance of the program you want to run
    Dim app As Object
    Set app = CreateObject("Powerpoint.Application")

    ' Show the program's user interface
    app.Visible = True
End Sub

2 thoughts on “Excel VBA Run External Program”

  1. Wow that was unusual. I just wrote an incredibly long comment but after I clicked submit my comment didn’t appear. Grrrr… well I’m not writing all that over again. Anyways, just wanted to say superb blog!

  2. Unquestionably believe that which you stated. Your favorite reason appeared to be on the internet the simplest thing to be aware of. I say to you, I certainly get irked while people consider worries that they plainly do not know about. You managed to hit the nail upon the top as well as defined out the whole thing without having side effect , people could take a signal. Will likely be back to get more. Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

Share this Doc
Jump to Topics
SOLVED EXCEL
Scroll to Top