VBA & Macro Problems

Open a Word Document from an Alternate File Path with VBA

Maira MehtabMaira Mehtab Nov 22, 2026 868 views

Question details

Open a source Word document from a primary path or an alternate path when the file has not yet been moved.

Open a Word Document from an Alternate File Path with VBA
Product
Microsoft Word VBA
Device & OS
not provided
Scenario
A macro reads a table of procedure categories from a source document that may be in different folders during a migration.
Observed behavior
The macro needs to check both locations and open the available source document without a file-not-found error.
Before you start

Confirm the full paths and file name for both possible source locations. Open the macro in Word's Visual Basic Editor and ensure macros are enabled for the trusted document.

Solution 1Recommended

Check Both Paths Before Opening the Source Document

Use FileSystemObject to select the first existing path and show a message if the document is missing from both locations.

This Windows VBA example uses late binding, so you do not need to add a FileSystemObject reference. Replace the example paths with the locations used by your organization.

1
Open the VBA editor

In Word, press Alt+F11 and open the module that contains your macro, or choose Insert > Module to create one.

2
Add the path check

Paste the following example into the module and update both paths: Sub OpenSourceDocument() Dim fso As Object Dim sourceDoc As Document Dim primaryPath As String Dim alternatePath As String primaryPath = "C:\Procedure Macros\Procedure Types 2010.doc" alternatePath = "C:\Document & Data Services\Documents Ready to Process\Procedure Master Templates\Procedure Types 2010.doc" Set fso = CreateObject("Scripting.FileSystemObject") If fso.FileExists(primaryPath) Then Set sourceDoc = Documents.Open(FileName:=primaryPath) ElseIf fso.FileExists(alternatePath) Then Set sourceDoc = Documents.Open(FileName:=alternatePath) Else MsgBox "The source document was not found in either location.", vbExclamation Exit Sub End If ' Add your table-processing code here, using sourceDoc. End Sub

3
Run the macro

In the VBA editor, place the cursor inside OpenSourceDocument and press F5. Test with the file in each location, then test with it absent from both.

4
Continue processing the table

In the module, place your existing table-reading and bookmark-insertion code after the If block, using sourceDoc to refer to the document that was opened.

Check Both Paths Before Opening the Source Document
File access errors: FileExists checks whether a path exists, but Documents.Open can still fail because of permissions, a damaged file, or another access issue. Add error handling if your workflow needs to manage those cases.
Free Microsoft Office alternative

Work with Word Documents in WPS Office

WPS Office is a free, lightweight alternative for opening and editing documents in a familiar interface. Its Microsoft Word format compatibility helps you move everyday document work between suites, although it does not fix Word VBA errors.

Open and edit source documents containing procedure tablesCompatible with Microsoft Word DOC and DOCX formatsFamiliar document-editing interface for easier migrationFree and lightweight for everyday office work
microsoft office alternative - wps office

Frequently Asked Questions

Which path does the macro use if the file exists in both locations?

The example checks primaryPath first and opens it when it exists. The alternatePath is checked only if the primary file is absent.

What happens if the document is missing from both folders?

The Else block displays a message and exits the macro before Documents.Open is called. Check both path strings and the file name in the VBA editor.

Do I need to add a reference for FileSystemObject?

Not for this Windows example. CreateObject("Scripting.FileSystemObject") uses late binding, so a reference does not need to be selected in Tools > References.

Does the macro move the source document?

No. The code only checks the two paths and opens an existing file. Moving the document requires separate code or a manual action.

Why might Documents.Open still fail when FileExists returns true?

The file may exist but be inaccessible because of permissions, file corruption, or another access issue. Add a VBA error handler around Documents.Open to report or manage those errors.