How to import a file where the file name is in an Excel workbook

BoonBeats

New Member
Joined
Mar 10, 2009
Messages
2
Hi,
I've been trying to get my head around this but have hit a brick wall.
So here's my question.

I'm writing a Macro to import a particular text file daily. Now the thing is the file name is in a cell on sheet1 cell "I8" on an excel workbook.

Can someone help me with the coding of this please.

the peice of code below is what i have so far but it isn't working.

Sheets("Data").Select
Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;G:\Common\Joey\QHFSGEO_T" & Sheet1!I8 & ".TXT", Destination:=Range("$A$1"))
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hi
try these codes
Code:
Dim a As String
a = "TEXT;G:\Common\Joey\QHFSGEO_T\" & Sheets("Sheet1").Range("I8") & ".TXT"
With ActiveSheet.QueryTables.Add(Connection:= _
a, Destination:=Range("$A$1"))
Ravi
 
Upvote 0
Hey,

That worked perfectly fine! Many Thanks! :)



Hi
try these codes
Code:
Dim a As String
a = "TEXT;G:\Common\Joey\QHFSGEO_T\" & Sheets("Sheet1").Range("I8") & ".TXT"
With ActiveSheet.QueryTables.Add(Connection:= _
a, Destination:=Range("$A$1"))
Ravi
 
Upvote 0

Forum statistics

Threads
1,214,668
Messages
6,120,825
Members
448,990
Latest member
rohitsomani

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