View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.misc
Steve Yandl Steve Yandl is offline
external usenet poster
 
Posts: 284
Default how do I import .txt file as rows not columns?

Phil,

Copy what is between the lines so it's ready to paste.

Open a new Excel workbook.

Hold down 'Alt' and press the 'F11' key.

In the upper left of the Visual Basic Editor window, you will find a smaller
project window with a tree type representation of workbook and sheets. The
top level will probably read "VBAProject (Book1)". Right click the
'VBAProject (Book1)' and choose 'Insert Module'. When you do so, a new
folder appears named 'Modules' along with 'Module 1' which you are now in.
The large empty window to the right is the code window. Paste what I
provided into that code window.

Edit the line that reads:
strTxtFilePath = "C:\Test\AddyList.txt"
so that it points to the actual text file where the semi-colon separated
email addresses reside or you can create a folder "C:\Test' on your system,
move a copy of your text file into that folder and rename it AddyList.txt if
you prefer.

Close the Microsoft Visual Basic window and you will be back in your empty
workbook. Now, press 'Alt' plus 'F8' and you will find your macros in a
list. If you have more macros than the one we just pasted, make sure that
"GetMailList()" is the one selected and then click the 'Run' button. Now,
just sit back and let the subroutine deliver.

Steve



"Phil Zack" wrote in message
...
Thanks Steve,

Sorry to sound dim, but what DO I actually do with this program?

Do I paste it somewhere and click run, or do I need to go into DOS and
type
it in, or what?

Thanks,

Phil

"Steve Yandl" wrote:

Phil,

Try this subroutine. Just edit the line that defines the path to your
actual text file.

_______________________________________

Sub GetEmailList()
Const ForReading = 1

strTxtFilePath = "C:\Test\AddyList.txt"

Set FSO = CreateObject("Scripting.FileSystemObject")
Set objFile = FSO.OpenTextFile(strTxtFilePath, ForReading)

strText = objFile.ReadAll
objFile.Close

strText = Replace(strText, vbCrLf, "")
arrText = Split(strText, ";")

For R = 0 To UBound(arrText)
Cells(R + 1, 1).Value = Trim(arrText(R))
Next R

Set FSO = Nothing
End Sub
_______________________________________

Steve




"Phil Zack" <Phil wrote in message
...
I have a text file of several hundred email addresses, which I want to
import
into Excel (or Access). The data look like:

; ; ... etc

but when I use the Import External Data wizard, it imports the whole
lot
as
columns in the first row, and cuts off the last few hundred, as there
are
more than 255 records, so what I get looks like:

A / B /
C /
1/
/ /

How can I import them as single column entries in many rows? What I
want
is
this:

A /
1/
/
2/
/
3/
/

Thanks in anticipation,

Phil