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
 
RoryA, many thanks for your code. Works perfectly with a slight moderation. I discovered that one of the files in the directory (files are named after staff members) had an apostrophe in the name which appeared to be causing the #ref. Ive modified the code so the line before yours is
Excel Formula:
mylook = Replace(f.Name, "'", "''")
and then replaced f.name in your code with mylook
really greatful for your help
 
Upvote 0

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Look at Power Query. There is an option to scan the directory which could be loaded into a worksheet. This can be done without opening the workbook.
 
Upvote 0

Forum statistics

Threads
1,215,148
Messages
6,123,301
Members
449,095
Latest member
Chestertim

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