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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

ravishankar

Well-known Member
Joined
Feb 23, 2006
Messages
3,566
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

BoonBeats

New Member
Joined
Mar 10, 2009
Messages
2
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,191,607
Messages
5,987,633
Members
440,104
Latest member
thigarette

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
Top