Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Importing text files into same workbook.

I need to import approx. 25 text files into an Excel workbook from a
directory. Import each text file into a different worksheet of the
workbook. Starting in row 2.

The name of the worksheet should correspond to the name of the text
file.

The records in the text files are delimited bt the pipe"|" symbol.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Importing text files into same workbook.

See this example
http://www.rondebruin.nl/txtcsv.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"rkckjk" wrote in message
...
I need to import approx. 25 text files into an Excel workbook from a
directory. Import each text file into a different worksheet of the
workbook. Starting in row 2.

The name of the worksheet should correspond to the name of the text
file.

The records in the text files are delimited bt the pipe"|" symbol.

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Importing text files into same workbook.

Try this code. Change Folder name as required

Sub add_files()

Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Const Delimiter = ","
Set fsread = CreateObject("Scripting.FileSystemObject")

Folder = "C:\temp"

First = True
Do
If First = True Then
FName = Dir(Folder & "\" & "*.txt")
First = False
Else
FName = Dir()
End If
If FName < "" Then
ThisWorkbook.Worksheets.Add
Set NewSht = ActiveSheet
RowCount = 2

Set fread = fsread.GetFile(FName)
Set tsread = fread.OpenAsTextStream(ForReading, TristateUseDefault)
NewSht.Name = Left(fread.shortname, Len(fread.shortname) - 4)

Do While tsread.atendofstream = False

InputLine = tsread.ReadLine

'extract comma seperated data
ColumnCount = 1
Do While InputLine < ""
DelimiterPosition = InStr(InputLine, Delimiter)
If DelimiterPosition 0 Then
Data = Trim(Left(InputLine, DelimiterPosition - 1))
InputLine = Mid(InputLine, DelimiterPosition + 1)
Else
Data = Trim(InputLine)
InputLine = ""
End If

NewSht.Cells(RowCount, ColumnCount) = Data
ColumnCount = ColumnCount + 1
Loop
RowCount = RowCount + 1
Loop

tsread.Close

End If

Loop While FName < ""
End Sub

"Ron de Bruin" wrote:

See this example
http://www.rondebruin.nl/txtcsv.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"rkckjk" wrote in message
...
I need to import approx. 25 text files into an Excel workbook from a
directory. Import each text file into a different worksheet of the
workbook. Starting in row 2.

The name of the worksheet should correspond to the name of the text
file.

The records in the text files are delimited bt the pipe"|" symbol.

Thanks



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 all files in a folder to excel workbook kmcosta Excel Programming 2 December 29th 06 02:33 AM
importing multiple text files into individual worksheets in workbook [email protected] Excel Programming 2 September 21st 06 10:53 PM
Importing Text Files smith_gw Excel Discussion (Misc queries) 1 May 5th 05 10:42 PM
Importing text files Dominique Feteau[_2_] Excel Programming 1 December 16th 04 12:25 PM
Importing multiple text files into single workbook Steve[_56_] Excel Programming 1 January 15th 04 08:18 PM


All times are GMT +1. The time now is 06:12 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"