macro for import of csv .txt file?

R

Ryan Cain

How do I automate the process of importing a CSV .TXT file into an empty
worksheet and placing it in rows and columns in Excel starting in cell A1?
How will the macro select comma and tab delimited and possibly "unicode" text
for Excel 2003 so that my values in the CSV .txt file are put into separate
cells in Excel?

I would like to know how to do this in Excel 2000 and 2003.
 
T

Tim Williams

Here's a sub which will open a file and copy the contenets to a
specified location, then close the file

Sub PlaceFile(sPath As String, CopyTo As Range)

Dim wb As Workbook

Workbooks.OpenText Filename:=sPath, Origin:=437, _
StartRow:=1, DataType:=xlDelimited,
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Semicolon:=False, Comma:=True
With ActiveWorkbook
.Worksheets(1).UsedRange.Copy CopyTo
.Close False
End With

End Sub


Sub Tester()
PlaceFile "C:\Analysis\tempFile.txt", ActiveSheet.Range("A1")
End Sub


Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top