VBA & Macro Problems

How to Set a Default Folder Path in Word VBA Folder Picker

Adam DavisAdam Davis Oct 22, 2026 870 views

Question details

The user needs a Word VBA macro to automatically open a specific directory when launching a folder picker dialog.

How to Set a Default Folder Path in a Word VBA Folder Picker
Product
Microsoft Word
Device & OS
not provided
Scenario
Writing a VBA macro to select DOCX files from a specific default folder rather than the system's default directory.
Observed behavior
The folder picker needs to be configured programmatically to open directly at the specified default path.
Before you start

Ensure you have the Developer tab enabled in your Word ribbon and have basic familiarity with navigating the Visual Basic Editor (VBE).

Solution 1Recommended

Use Application.FileDialog with InitialFileName Property

Use the FileDialog object configured as a folder picker (msoFileDialogFolderPicker) and assign your target directory to its InitialFileName property.

The most reliable way to prompt a user for a folder while starting in a specific directory is using the Application.FileDialog(4) method. The number 4 represents the msoFileDialogFolderPicker constant.

By setting the .InitialFileName property before calling the .Show method, you force the dialog box to navigate directly to your desired path.

1
Open the VBA Editor

Press ALT + F11 to open the Visual Basic Editor in Word, then go to Insert > Module to create a new macro script.

2
Create the Folder Picker Function

Copy and paste the following code to create a reusable function: Function GetFolder(Optional DefaultPath As String) As String With Application.FileDialog(4) .InitialFileName = DefaultPath If .Show Then GetFolder = .SelectedItems(1) End With End Function

3
Call the Function in Your Macro

In your main macro, call the newly created function and pass the specific folder path you want to open by default: Sub SelectMyFolder() Dim strInFolder As String strInFolder = GetFolder(DefaultPath:="G:\MyDocs\German\") MsgBox "You selected: " & strInFolder End Sub

Use Application.FileDialog with InitialFileName Property
Path Formatting: Ensure your default path ends with a backslash (e.g., "G:\MyDocs\"). If the specified path does not exist on the user's computer, the folder picker will revert to the default Documents folder.
Advanced Macro Support

Run VBA Macros Seamlessly in WPS Office

You can execute this exact FileDialog VBA code in WPS Writer. WPS Office provides excellent macro support, allowing you to run, edit, and create VBA scripts with a familiar Visual Basic Editor interface.

  1. 1. Download and Install: Download WPS Office and ensure the VBA module is enabled during or after installation.
  2. 2. Open WPS Writer: Launch WPS Writer and navigate to the Developer tab on the top ribbon.
  3. 3. Access the VBA Editor: Click on 'Visual Basic' or 'Macros' to open the code editor.
  4. 4. Run Your Code: Insert a new module, paste your FileDialog macro code, and run it just as you would in Microsoft Word.
Fully compatible with standard Word VBA syntax and Application.FileDialog methods.High format compatibility with Microsoft Word .docm and .dotm macro-enabled files.Built-in Visual Basic Editor allows you to write and debug code seamlessly.Free, lightweight, and incredibly fast to install.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my VBA folder picker open in the Documents folder instead of my default path?

If the path assigned to `InitialFileName` is misspelled, lacks proper drive letters, or does not exist on the specific computer running the macro, VBA will ignore the invalid path and safely fall back to the system's default Documents folder.

How do I select a file instead of a folder using VBA?

To select files, change `Application.FileDialog(4)` to `Application.FileDialog(3)`. The number 3 represents the `msoFileDialogFilePicker` constant, which allows users to browse and select individual files rather than directories.

Can I use a network drive path as the default folder in VBA?

Yes, you can use mapped drive letters (like `Z:\Shared\`) or UNC network paths (like `\\ServerName\SharedFolder\`) as the `DefaultPath` string. The user must have active network access to that location for the dialog to open it successfully.

How do I clear the default path so it opens the last used folder?

Simply omit the `InitialFileName` assignment or set it to an empty string `""`. Without a specified initial file name, the FileDialog typically remembers and opens the folder that was last accessed by the user.