Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Open text files as Worksheets in a workbook

On approximately Fri, 25 Apr 2003 22:20:06 +0100, "Ong, Seng"
said something to the effect of:

Hi!

SOS! Would someone please enlighten me on how to do that?

I desperately need a routine to open files from a folder and import them
into separate worksheets instead of separate workbooks.

And, would someone please tell me which site has got the most comprehensive
collection of Macro source code that I can copy and adapt to use?

Thanks so much!

Seng



Sub TextFileToSheet(ByVal FName As String, ByVal Sh As String)
Dim Row As Long
Dim TextLine As String
Row = 1
Application.ScreenUpdating = False
On Error GoTo Bottom:
Open FName For Input As #1
While Not EOF(1)
Line Input #1, TextLine
If Not EOF(1) Then
Sheets(Sh).Cells(Row, 1).Value = TextLine
Row = Row + 1
End If
Wend
Bottom:
Application.ScreenUpdating = True
Close #1
End Sub

You can get much fancier than this, like looking for delimiting
characters, stripping out characters other than alphanumerics and
punctuation, checking to ensure the sheet and file actually exist,
etc., but this is one basic way to do what you wanted. Another way
(cheater's method) is to use Workbooks.OpenText and let it create a
new workbook, but then copy the only sheet from that workbook into
your own workbook, rename the sheet, and close the unneeded new
workbook. But there's something to be said for controlling the
process yourself. :)

-Binarian
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
Several files open from workbook, how to do that? artzuka Excel Discussion (Misc queries) 3 January 6th 09 09:03 PM
how do i open excel files in different worksheets? camila Excel Discussion (Misc queries) 1 January 9th 08 04:29 PM
Open multiple files into multiple worksheets of the same workbook lil Matt Excel Discussion (Misc queries) 1 October 31st 06 09:03 PM
i can't see any worksheets when I open a workbook Mim Excel Discussion (Misc queries) 3 June 21st 06 09:05 PM
How do I open several worksheets from the same workbook on screen Innovman 2006 Excel Worksheet Functions 4 June 12th 06 04:57 PM


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