I'm trying to create a macro to import a .txt file into excel and fill in column A. Each word in the text file should have its own row. So far I have code which will allow the user to select a .txt file, reads it, and writes each word in its own cell. It does not, however, start a new row with each word. Any and all help is appreciated. Thanks!
I'm starting with simple text files, though it would be nice to know how to edit out all punctuation as well when importing. (see two examples below)
EX1: "The quick brown
fox jumped over
the lazy moon"
EX2: "The quick.
brown fox,
jumped over the?
lazy moon"
And my code...
Sub TextImport()
Dim fileToOpen As String
Worksheets("Dictionary").Activate
Application.ScreenUpdating = False
Range("a:z").Delete
fileToOpen = Application.GetOpenFilename("Text Files (*.txt), *.txt", , "Select a file to import")
If fileToOpen <> "" Then
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" _
& fileToOpen, Destination:=Range("A1"))
.Name = "mytext"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileSpaceDelimiter = True
.Refresh BackgroundQuery:=False
End With
End If
Application.ScreenUpdating = False
End Sub