Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Several files open from workbook, how to do that? | Excel Discussion (Misc queries) | |||
how do i open excel files in different worksheets? | Excel Discussion (Misc queries) | |||
Open multiple files into multiple worksheets of the same workbook | Excel Discussion (Misc queries) | |||
i can't see any worksheets when I open a workbook | Excel Discussion (Misc queries) | |||
How do I open several worksheets from the same workbook on screen | Excel Worksheet Functions |