How to Retrieve a Value from a Dynamic External Excel Reference
Question details
The user needs to pull data from an external Excel file where the file path, workbook name, sheet name, and cell address are dynamically generated by concatenating text.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Attempting to use a concatenated text string representing an external file path to pull data from a closed workbook into the current spreadsheet.
- Observed behavior
- Excel treats the concatenated file path as standard text rather than an executable reference. Standard functions like INDIRECT return errors if the external workbook is closed, preventing the formula from resolving dynamically.
Verify the exact file path, workbook name, and sheet name of your target external file. Since the most reliable solution involves VBA macros, ensure your Macro Security settings allow execution and that the Developer tab is enabled in your ribbon.
Retrieve Dynamic External Values Using a Custom VBA Function
Because standard formulas cannot evaluate a dynamic text path to a closed workbook, a custom VBA function utilizing ExecuteExcel4Macro is the most effective approach.
The ExecuteExcel4Macro method allows VBA to execute Excel 4.0 macro functions, which can retrieve a value from a closed external workbook without needing to physically open the file in the background.
By writing a custom user-defined function (UDF) in VBA, you can pass the path, file, sheet, and cell reference dynamically, which VBA will construct and evaluate.
Enable the Developer tab in Excel, then click on 'Visual Basic' or press ALT + F11 on your keyboard to open the VBA Editor.
In the VBA Editor menu, click 'Insert' and select 'Module' to create a new standard code module.
Create a function (for example, GetValue) that accepts arguments for path, file, sheet, and range. Inside the function, construct the reference string and apply ExecuteExcel4Macro to return the target value.
Click 'File' > 'Save As' and ensure you select 'Excel Macro-Enabled Workbook (*.xlsm)' from the file format dropdown.
Return to your active worksheet and use the newly created function like a regular formula, e.g., =GetValue("C:\Users\PC\Documents\", "B.xlsx", "Sheet1", "A1").

Import Data Dynamically Using Power Query
If you are not familiar with VBA and want a low-code alternative, Power Query can be parameterized to dynamically import data from external workbooks.
Easily Handle Advanced Formulas and VBA with WPS Spreadsheet
WPS Spreadsheet offers robust built-in support for advanced data manipulation, custom functions, and VBA macros, allowing you to efficiently build dynamic references and process complex datasets without restrictions.
- 1. Download and Install WPS Office: Download WPS Office for free and open WPS Spreadsheet.
- 2. Open Your Workbook: Open the workbook where you wish to build dynamic external references.
- 3. Launch the VBA Editor: Navigate to the 'Developer' tab and click 'Visual Basic' to insert your custom ExecuteExcel4Macro script.
- 4. Save and Run: Save your file as a Macro-Enabled Workbook and run your dynamic reference formulas smoothly.

Frequently Asked Questions
Why doesn't the INDIRECT function work for closed external workbooks?
The INDIRECT function in Excel is designed to evaluate dynamic text strings into cell references, but it strictly requires the referenced external workbook to be open in the background. If the target workbook is closed, INDIRECT will return a #REF! error.
What is ExecuteExcel4Macro and how does it help?
ExecuteExcel4Macro is a legacy VBA method that executes Microsoft Excel 4.0 macro functions. It is highly valuable for this specific scenario because it possesses the unique capability to extract values from a closed external workbook without explicitly opening the file.
Can I achieve dynamic external references without using VBA or Power Query?
Generally, no. Without VBA scripts or Power Query parameters, native Excel formulas cannot evaluate a dynamically constructed text string into an actionable reference for a closed workbook.
How do I resolve macro security warnings when using custom VBA functions?
To manage macro security, go to File > Options > Trust Center > Trust Center Settings > Macro Settings. Select 'Disable all macros with notification' so you can manually approve the execution of your custom dynamic reference script each time you open the workbook.




