How to Open a Folder Automatically at the End of a Word Macro
Question details
The user wants to automatically open a specific folder in Windows Explorer immediately after a Word macro finishes executing.

- 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.
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.
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.
Press Alt + F11 to open the Visual Basic for Applications (VBA) editor in your word processor.
Navigate to the module containing your macro and scroll to the end of the script, right before the 'End Sub' statement.
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".
Insert the following code to call Windows Explorer: Shell "explorer.exe " & FolderPath, vbNormalFocus.
Save your macro and run it. Once the macro completes its tasks, the specified folder will automatically pop open in a new Explorer window.

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. Install WPS Office: Download and install the latest version of WPS Office on your computer.
- 2. Open the Developer Tab: Launch WPS Writer and navigate to the 'Developer' tab to access the macro tools.
- 3. Run Your Code: Click on 'Visual Basic' to paste your Shell script, save your macro, and execute your automated tasks effortlessly.

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.




