logo
search
VBA & Macro Problems

How to Open a Folder Automatically at the End of a Word Macro

Tauseeq MagsiTauseeq Magsi Oct 10, 2026 868 views

Question details

The user wants to automatically open a specific folder in Windows Explorer immediately after a Word macro finishes executing.

How to Open a Folder Automatically at the End of a Word Macro
Product
Word
Device & OS
Windows
Scenario
Running a macro that generates or saves files, and needing to immediately access the destination folder to view the output without navigating manually.
Observed behavior
Using the ChangeFileOpenDirectory statement only changes the default file location for Save/Open dialogs, but it fails to physically open the folder window for the user.
Before you start

Ensure your document is saved in a macro-enabled format (such as .docm) and that you have enabled macros in your security settings so the VBA script can execute properly.

Solution 1Recommended

Use the VBA Shell Function to Open Windows Explorer

Trigger Windows Explorer to open a designated folder path using the Shell command at the end of your macro script.

While the ChangeFileOpenDirectory command is useful for setting the working directory for file dialog boxes, it cannot open a File Explorer window. To physically open a folder on your screen, you must interact with the Windows OS directly using the VBA Shell function.

1
Open the VBA Editor

Press Alt + F11 to open the Visual Basic for Applications (VBA) editor in your word processor.

2
Locate Your Macro

Navigate to the module containing your macro and scroll to the end of the script, right before the 'End Sub' statement.

3
Define the Folder Path

Declare a string variable and set it to your desired folder path. For example, type: Dim FolderPath As String, and on the next line: FolderPath = "C:\Form".

4
Add the Shell Command

Insert the following code to call Windows Explorer: Shell "explorer.exe " & FolderPath, vbNormalFocus.

5
Save and Run

Save your macro and run it. Once the macro completes its tasks, the specified folder will automatically pop open in a new Explorer window.

Use the VBA Shell Function to Open Windows Explorer
Syntax Formatting: Make sure there is a space after explorer.exe inside the quotation marks (i.e., "explorer.exe "). Without this space, the command will fail to recognize the folder path.
Advanced Document Automation

Run VBA Macros Seamlessly in WPS Writer

WPS Office provides robust support for VBA macros, allowing you to automate repetitive tasks, manage file directories, and enhance your document workflows seamlessly using standard VBA code.

  1. 1. Install WPS Office: Download and install the latest version of WPS Office on your computer.
  2. 2. Open the Developer Tab: Launch WPS Writer and navigate to the 'Developer' tab to access the macro tools.
  3. 3. Run Your Code: Click on 'Visual Basic' to paste your Shell script, save your macro, and execute your automated tasks effortlessly.
Full support for standard VBA macro scripts and automated tasksHighly compatible with Microsoft Word (.docm) formatsLightweight application with fast macro execution speedsFamiliar user interface for editing and managing code
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't my VBA Shell command working?

The most common reason for the Shell command failing is a missing space in the syntax. Ensure there is a space after 'explorer.exe' before the closing quote (e.g., Shell "explorer.exe " & FolderPath). Also, verify that the target folder path actually exists on your computer.

Can I open a specific file instead of a folder at the end of a macro?

Yes, you can modify the Shell command to open a specific file by including the file's full path and name. However, you typically need to specify the application executable (like notepad.exe or excel.exe) before the file path, or use the ShellExecute API for default applications.

Does ChangeFileOpenDirectory affect the Shell command?

No, ChangeFileOpenDirectory only changes the default directory that appears when you click 'File > Open' or 'File > Save As'. It has no impact on the Windows Explorer window opened by the Shell command.

Will this VBA Shell command work on a Mac?

No, the 'Shell "explorer.exe..."' command is specific to the Windows operating system. For macOS, you would need to use the MacScript function or AppleScript commands to open a Finder window.