Get data from closed workbook

JohnRyan

New Member
Joined
Jan 4, 2014
Messages
9
I'm trying to get data from Cell A4 in a closed workbook named "Test1.xlsm"
When I use the name "Test1.xlsm" it gets the data
But when I put the file name "Test1.xlsm" into a string it doesn't return the data from Cell A4


Sub LoopThroughFiles_for_Total_Values()


Dim Date2 As String
Dim strFileName As String


strFileName = "Test1.xlsm"

'Date2 = "='F:\[strFileName]Sheet1'!a4" This line doesn't return the contents from the closed workbook "Test1.xlsm"
Date2 = "='F:\[Test1.xlsm]Sheet1'!a4" This line returns the contents form the closed workbook "Test1.xlsm"


Range("A1") = [Date2]


End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try...

Code:
Date2 = "='F:\[" & strFileName & "]Sheet1'!a4"

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,215,676
Messages
6,126,162
Members
449,295
Latest member
DSBerry

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