Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default mporting multiple text files into Excel with corresponding filenames

Dear members,

I need to import 100+ text files into Excel.

In addition I want Excel to show corresponding filename (where the
data comes from) in each row.

How do I accomplish this?
TIA
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,480
Default mporting multiple text files into Excel with corresponding filenames

Hi

Take a look at Ron de Bruin's site. He has lots of code examples to
consolidate files.
http://www.rondebruin.nl/tips.htm
--
Regards
Roger Govier

"avi" wrote in message
...
Dear members,

I need to import 100+ text files into Excel.

In addition I want Excel to show corresponding filename (where the
data comes from) in each row.

How do I accomplish this?
TIA

__________ Information from ESET Smart Security, version of virus
signature database 4830 (20100203) __________

The message was checked by ESET Smart Security.

http://www.eset.com




__________ Information from ESET Smart Security, version of virus signature database 4830 (20100203) __________

The message was checked by ESET Smart Security.

http://www.eset.com



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default mporting multiple text files into Excel with corresponding filenam

Specify the folder and try the below..

Sub Macro()

Dim strFolder As String, strFile As String
Dim strData As String, intFile As Integer, lngRow As Long

strFolder = "D:\PhoneNo"
If Right(strFolder, 1) < "\" Then strFolder = strFolder & "\"

strFile = Dir(strFolder & "*.txt", vbNormal)
Do While strFile < ""
intFile = FreeFile
Open strFolder & "\" & strFile For Input As #intFile
Do While Not EOF(intFile)
Line Input #intFile, strData
lngRow = lngRow + 1
Range("A" & lngRow) = strFile
Range("B" & lngRow) = strData
Loop
Close #intFile
strFile = Dir
Loop


End Sub

--
Jacob


"avi" wrote:

Dear members,

I need to import 100+ text files into Excel.

In addition I want Excel to show corresponding filename (where the
data comes from) in each row.

How do I accomplish this?
TIA
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default mporting multiple text files into Excel with correspondingfilenam

Thanks Jacob! Works perfect!
Just one note (that I forgot to mention): data in my text files is
comma delimited.
Your code imports correctly filenames & data BUT all the data is
imported into one cell.
OK, I can use "text to columns" but would like to have it
delimited.... :-)

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default mporting multiple text files into Excel with corresponding fil

That was not mentioned in the original post..I have modified to suit your
requirement.

Sub Macro()

Dim strFolder As String, strFile As String, lngRow As Long
Dim strData As String, arrData As Variant, intFile As Integer

strFolder = "D:\PhoneNo"
If Right(strFolder, 1) < "\" Then strFolder = strFolder & "\"

strFile = Dir(strFolder & "*.txt", vbNormal)
Do While strFile < ""
intFile = FreeFile
Open strFolder & "\" & strFile For Input As #intFile
Do While Not EOF(intFile)
Line Input #intFile, strData
arrData = Split(strData, ",")
lngRow = lngRow + 1
Range("A" & lngRow) = strFile
Range("B" & lngRow).Resize(, UBound(arrData) + 1) = arrData
Loop
Close #intFile
strFile = Dir
Loop


End Sub

--
Jacob


"avi" wrote:

Thanks Jacob! Works perfect!
Just one note (that I forgot to mention): data in my text files is
comma delimited.
Your code imports correctly filenames & data BUT all the data is
imported into one cell.
OK, I can use "text to columns" but would like to have it
delimited.... :-)

.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default mporting multiple text files into Excel with corresponding fil

Jacob Skaria wrote:
* * arrData = Split(strData, ",")


That will fail if a quoted value contains a comma.

Phil Hibbs.
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default mporting multiple text files into Excel with corresponding fil

Why ?

"Phil Hibbs" wrote in message
...
Jacob Skaria wrote:
arrData = Split(strData, ",")


That will fail if a quoted value contains a comma.

Phil Hibbs.


Reply
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 03:25 AM.

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

About Us

"It's about Microsoft Excel"