Import .txt files

  • Thread starter Thread starter Rocky McKinley
  • Start date Start date
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
 
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
 
Back
Top