macro for import of csv .txt file?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 
Back
Top