LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default mporting multiple text files into Excel with corresponding fil

Hi Phil

Thanks for your thoughts. We are not sure since the OP has not come back. A
better way would be to use the .OpenText method as below...

Workbooks.OpenText Filename:="D:\PhoneNo\2.txt", StartRow:=1 , _
DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, Comma:=True


--
Jacob


"Phil Hibbs" wrote:

I would probably go with a solution that involves using the Excel
import code to read each file into a blank tab, and then copy that
data from the tab into the combined tab. Here's an example of a macro
that imports data into a new tab:

ActiveWorkbook.Worksheets.Add
ActiveSheet.Name = "Tempsheet"

With ActiveSheet.QueryTables.Add(Connection:="TEXT;" _
+ FileName, Destination:=Range("A1"))
.Name = "CSVfile"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 2, 2, 2, 2, 2, 2, _
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, _
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, _
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, _
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2)
.Refresh BackgroundQuery:=False
End With

The big 2, 2, 2, 2, 2 line defines all columns (up to 100) as Text.
Next you would need to copy-paste the contents of this tab into the
real tab and fill in the file name, then delete the tab and import the
next file. You could turn off screen updates while this is happening.
Or hide the temporary tab.

Phil Hibbs.
.

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
importing multiple text files into Excel with corresponding filenames avi[_2_] Excel Programming 2 February 3rd 10 12:07 PM
Joel - Importing multiple text files to 1 spreadsheet, now importing from excel files Volker Hormuth Excel Programming 7 April 9th 09 06:55 PM
multiple text files to multiple rows in excel Vindhyawasini Excel Programming 1 January 3rd 08 03:04 AM
excel files in my docs have numbered filenames and are duplicates sss Setting up and Configuration of Excel 1 December 11th 07 11:37 PM
Acquiring filenames for multiple files with GetOpenFilename John Excel Programming 1 December 17th 03 06:51 AM


All times are GMT +1. The time now is 02:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"