Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / September 2004

Tip: Looking for answers? Try searching our database.

How do I use a macro to Import mutiple .txt files into excel 2000?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Desperate Andy - 30 Sep 2004 10:37 GMT
I've got as far as Importing a single file into a specific location (A:1) But
I need to produce a macro that consults multiple .txt files and appends them
to individual excel lines.

Any help or guidance would be greatly appreciated

Andy
Bernie Deitrick - 30 Sep 2004 15:32 GMT
Andy,

If all your text files are .txt files, and are in the same folder, then try
the macro below. One big assumption is that the files have data in column A
when imported, and that there aren't any empty rows or columns separating
the data. You may also need to change some of the parameters in the OpenText
command - the best way is to record a macro while opening one of your files.

HTH,
Bernie
MS Excel MVP

Sub ConsolidateTextFiles()
With Application.FileSearch
   .NewSearch
   'Change this to your directory with the text files
   .LookIn = "C:\Excel"
   .SearchSubFolders = False 'Change to True if needed
   .FileType = msoFileTypeAllFiles
   If .Execute() > 0 Then
   Set Basebook = ThisWorkbook
       For i = 1 To .FoundFiles.Count
           If .FoundFiles(i) Like "*.txt" Then
           Workbooks.OpenText Filename:=.FoundFiles(i), Origin:= _
           xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
           xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True,
Semicolon:=False, _
           Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(1, 1)
           Range("A1").CurrentRegion.Copy
Basebook.Worksheets(1).Range("a65536").End(xlUp).Offset(1, 0)
           ActiveWorkbook.Close
           End If
        Next i
       Basebook.SaveAs Application.GetSaveAsFilename("Consolidated
file.xls")
   End If
End With
End Sub

> I've got as far as Importing a single file into a specific location (A:1) But
> I need to produce a macro that consults multiple .txt files and appends them
[quoted text clipped - 3 lines]
>
> Andy
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.