Import .txt files

R

Rocky McKinley

I need to import all txt files from a specified folder (C:\myfiles) into
Sheet1 one at a time.
They are space delimited, what is the best way to acheive this?
"my macro" extracts a little peice of data to another workbook it runs once
after each file is imported.

So import first txt file
Run "my macro"
Cells.Clear

import second txt file
Run "my macro"
Cells.Clear

import third
Run "my macro"
Cells.Clear
etc etc

Regards,
Rocky McKinley
 
T

Tom Ogilvy

Dim sh as Worksheet
Dim fName as String
set Sh = Activesheet
sh.Cells.ClearContents
fname = Dir("C:\Myfolder\*.txt")
Do While fname <> "" then
workbooks.Open "C:\Myfolder\" & fname
sh.Cells.ClearContents
activesheet.UseRange.copy Destination:=sh.Range("A1")
Activeworkbook.close Savechanges:=False
Call MyMacro
fName = Dir()
Loop
sh.Cells.ClearContents
sh.Activate

Untested
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top