VBA & Macro Problems

How to Get File Names from a Running Process with WMI in VBA

Tauseeq MagsiTauseeq Magsi Oct 26, 2026 868 views

Question details

The user needs to identify the specific file opened by a running process using WMI in VBA but encounters Run-time error 438 when accessing nested properties in the Watch window.

How to Get File Names from a Running Process with WMI in VBA
Product
VBA
Device & OS
not provided
Scenario
Attempting to extract the file name from a WMI process object using numeric index paths like objList.Item(1).Properties.Item(2).Value.
Observed behavior
The VBA script throws Run-time error 438: Object does not support this property or method when trying to evaluate the indexed property path.
Before you start

Ensure you have the necessary administrative privileges on your machine to query running processes via WMI, and verify that the WMI service is active.

Solution 1Recommended

Use Documented WMI Properties Instead of Indexes

Bypass Watch window indexes and directly query documented WMI Win32_Process properties such as CommandLine or ExecutablePath to avoid Run-time error 438.

The Watch window displays properties as an indexed collection, but accessing COM object properties via numeric indexes (like Item(2)) is often unsupported in VBA. Using explicit WMI property names ensures script stability and correctly retrieves the target process details.

1
Initialize the WMI Service

Set up the WMI service object in your VBA script using the GetObject method: Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2").

2
Execute the WMI Query

Query the specific process by name. For example: Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'Foxtrot.exe'").

3
Extract the CommandLine Property

Loop through the process collection and access the property directly using objProcess.CommandLine. This property usually contains the path to the executable followed by the file it opened.

4
Parse the File Name String

Use built-in VBA string functions such as InStr, Mid, or Replace to isolate the document file path from the rest of the command line string.

Use Documented WMI Properties Instead of Indexes
Proper Syntax Avoids Errors: Directly referencing .CommandLine or .ExecutablePath entirely bypasses the limitations that trigger Run-time error 438.
Free Microsoft Office alternative

Try WPS Office for Seamless Macro and Data Management

If you are encountering persistent macro issues or simply need a robust, cost-effective platform, WPS Office offers a powerful and lightweight alternative for your everyday document and spreadsheet needs. It provides a familiar interface and excellent compatibility with Microsoft Office formats.

  1. 1. Download WPS Office: Visit the official WPS Office website and download the free installation package.
  2. 2. Install the Software: Run the installer and follow the quick setup wizard to install the suite on your computer.
  3. 3. Enable Developer Tools: Open WPS Spreadsheet, navigate to the Developer tab, and start managing your macros seamlessly.
Free to use with a lightweight installationExcellent compatibility with Microsoft Office formats like XLSX and DOCXFamiliar tabbed user interface for easy navigationBuilt-in support for VBA macros in WPS Spreadsheet Pro
microsoft office alternative - wps office

Frequently Asked Questions

What does Run-time error 438 mean in VBA?

Run-time error 438 translates to 'Object doesn't support this property or method.' It occurs when you try to invoke a method or access a property that does not exist for the specific object reference, such as using an invalid numeric index in a WMI collection.

How can I view all properties of a running process in VBA?

You can iterate through the Properties_ collection of a Win32_Process object using a For Each loop in VBA to print all available property names and their current values directly to the Immediate Window.

Why is the CommandLine property empty for some processes?

The CommandLine property might return an empty string or Null if your VBA application does not have sufficient permissions (e.g., standard user vs. administrator) to read the process information of elevated programs, or if the process belongs to the SYSTEM account.