To check if an application is running in Excel VBA, the most reliable method is to use the GetObject function combined with an On Error Resume Next statement. If the application is open, GetObject returns a reference to it; if it is not, it triggers a runtime error, which you can catch to determine the application's status. This technique is essential for automating tasks across multiple programs, such as pushing data from Excel to Word or Outlook, without causing the macro to crash when the target program is closed.

What You'll Need

  • Microsoft Excel installed on a Windows PC.
  • The Visual Basic for Applications (VBA) editor enabled.
  • Basic knowledge of how to insert a module into a workbook.
  • The specific Class Name of the application you are checking (e.g., "Word.Application" or "Outlook.Application").

Step-by-Step

  1. Open the VBA Editor: Launch Microsoft Excel. Press Alt + F11 on your keyboard to open the Visual Basic for Applications editor window.
  2. Insert a New Module: In the Project Explorer pane on the left, right-click on your workbook name, select Insert, and then click Module. This creates a clean space to write your procedure.
  3. Declare Your Variables: At the top of your subroutine, declare a variable to hold the application object. Using a generic Object type is often safest for checking status. For example: Dim appInstance As Object.
  4. Implement Error Handling: Because GetObject throws a runtime error if the application is not found, you must tell VBA to ignore the error temporarily. Type On Error Resume Next immediately before the attempt to grab the application.
  5. Attempt to Get the Object: Use the GetObject function with the application's program ID. For example, to check for Microsoft Word, use: Set appInstance = GetObject("Word.Application").
  6. Check the Result: Immediately after the GetObject line, check if the appInstance variable is Nothing. If it is Nothing, the application is not running. If it contains an object, the application is active.
  7. Reset Error Handling: Once the check is complete, return VBA to its normal error-reporting state by typing On Error GoTo 0. This prevents other actual bugs in your code from being silently ignored.
  8. Define the Action: Use an If...Then...Else block to decide what happens next. For instance, if the app is not running, you might use CreateObject to launch it, or display a MsgBox telling the user to open the program first.

Common Mistakes

One of the most frequent errors is forgetting to include On Error Resume Next. Without this line, the moment GetObject fails to find the application, the entire macro will stop and display a "Run-time error '429': ActiveX component can't create object" message. This makes the check useless because the code crashes before it can even tell you the application isn't running.

Another common mistake is using CreateObject instead of GetObject when trying to check status. CreateObject does not check if the program is already open; instead, it forces a new instance of the application to start in the background. If your goal is to interact with a window the user already has open, CreateObject will fail to find that specific session and will instead create a hidden second copy of the app, leading to confusion and wasted system resources.

Users also frequently forget to reset the error handler. If you leave On Error Resume Next active for the entire duration of your macro, you will never see any errors. If you make a typo in a variable name or reference a cell that doesn't exist, VBA will simply skip that line and move to the next, making your code behave unpredictably and making debugging nearly impossible.

Tips

For better performance and stability, consider using "Late Binding." Late binding allows you to use the Object data type rather than referencing a specific library in the Tools > References menu. This is highly recommended if you plan to share your Excel file with other people who might have different versions of Office installed. If you use "Early Binding" (referencing a specific version of the Word library), the code may break on a computer that has a newer or older version of Word.

If you are checking for an application that does not have a standard COM object (like a web browser or a third-party utility), GetObject will not work. In those cases, you would need to use Windows API calls to check the process list. However, for almost all Microsoft Office products and many professional software suites, the GetObject method is the standard and most efficient approach.

To make your code more reusable, wrap the check into a Boolean function. Instead of writing the GetObject logic every time, create a function called IsAppRunning(appID As String) As Boolean. This allows you to simply call If IsAppRunning("Word.Application") Then anywhere in your project, keeping your main logic clean and readable.

Troubleshooting

If your code says the application is not running even when it clearly is, check the Program ID you are using. For example, using "Word" instead of "Word.Application" can sometimes cause failures depending on the system registry. Always use the full Class Name provided in the official documentation for that software.

If the macro freezes or becomes unresponsive when calling GetObject, it is likely that the target application is in "Modal" mode. This happens when a dialog box (like a "Save As" or "Options" window) is open in the other application. The target app is essentially "locked" and cannot respond to the VBA request. To fix this, ensure all dialog boxes in the target application are closed before running the macro.

If you receive a "Permission Denied" error, it may be because the application is running with different administrative privileges than Excel. For example, if you ran Word as an Administrator but Excel as a standard user, Windows security may block the GetObject request. Ensure both applications are launched with the same privilege level.

Frequently Asked Questions

Can I use this to check if a website is open in Chrome?

No, GetObject only works for applications that expose a COM (Component Object Model) interface. Web browsers like Chrome and Edge do not expose their application instances this way. To check for a browser, you would need to use a Windows API call to check the running processes list via tasklist or the WMI service.

What is the difference between GetObject and CreateObject?

GetObject looks for an existing instance of the application that is already running in memory. CreateObject ignores whether the app is open and starts a brand new instance of the application, which often starts as a background process invisible to the user.

Will this work on a Mac?

No, this specific method relies on the Windows COM architecture. VBA for Mac handles application interaction differently and does not support GetObject in the same way. You would need to use AppleScript via the AppleScriptTask command to achieve similar results on macOS.

Does checking for the application slow down my Excel workbook?

The check is extremely fast and takes a fraction of a second. However, if you place this check inside a loop that runs thousands of times, it could cause a noticeable lag. It is best to check for the application once at the start of your macro and store the result in a variable.

How do I find the correct Class Name for other apps?

For Microsoft apps, it is usually [AppName].Application. For other software, you can search the developer's documentation for "COM Class ID" or "ProgID." If the software does not support COM automation, this method cannot be used.