ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro for import of csv .txt file? (https://www.excelbanter.com/excel-programming/336456-macro-import-csv-txt-file.html)

Ryan Cain

macro for import of csv .txt file?
 
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.

Tim Williams

macro for import of csv .txt file?
 
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


"Ryan Cain" wrote in message
...
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.





All times are GMT +1. The time now is 02:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com