Data from closed workbook

gordsky

Well-known Member
Joined
Jun 2, 2016
Messages
556
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I currently have a line of code which will pull data from a closed workbook without opening it. Its part of a loop that goes through each file in the directory.
The code is
Excel Formula:
range("A" & i).Formula = "=INDEX('" & MyPath & "\[" & f.Name & "]HrsWrk'!D:D,14,1)"

This works by putting the formula into Cell A(i) which in turn returns the value from the closed book.

My Question is rather than putting the formula into the cell and have that pull the data is it possible to alter the code slightly so that the value goes into A(i) rather than the formula
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Is the number of files in the directory dynamic? How many files are you looking to pull data from?
 
Upvote 0
Is the number of files in the directory dynamic? How many files are you looking to pull data from?
hi yes the number of files is dynamic. The line above is part of a loop which runs through the directory and then it pastes the formula into column a with file name as part of the formula for each file. What i would like is to modif the formula slightly so the value goes into column a rather than a formula to pull the value
 
Upvote 0
Try:
VBA Code:
range("A" & i).Value = Evaluate("=INDEX('" & MyPath & "\[" & f.Name & "]HrsWrk'!D:D,14,1)")
 
Upvote 0
Hopefully you get some others to buy in, I couldn't get it to work on a "Closed" workbook.
For a quick and dirty solution, just add this line "after" your line as follows:
VBA Code:
range("A" & i).Value = range("A" & i).Value
 
Upvote 0
Hopefully you get some others to buy in, I couldn't get it to work on a "Closed" workbook.
For a quick and dirty solution, just add this line "after" your line as follows:
VBA Code:
range("A" & i).Value = range("A" & i).Value
thanks for trying, I had already thought of the dirty solution but was hoping to do it another way
 
Upvote 0
You could use:

Code:
range("A" & i).Value = Executeexcel4macro("INDEX('" & MyPath & "\[" & f.Name & "]HrsWrk'!C4,14,1)")

Note that you need to use R1C1 referencing
 
Upvote 0
Solution
RoryA - thanks however this gives the #ref error also
 
Upvote 0

Forum statistics

Threads
1,215,133
Messages
6,123,234
Members
449,092
Latest member
SCleaveland

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top