Problems with CSV file input
one way
read the data in using the OPEN method, then you control the input more
easily
use the READ LINE method to real a comma separated line of text out of your
file, the use the SPLIT command to break it into pieces
All you need to do then is from each into a cell....and if the cell is
formatted as TEXT then Excel won't try top convert it.
there are other ways to do this of course, but this is meant to be quite
simplistic
not tested, but this will help get you going
Option Explicit
Sub readCSV()
Dim ff As Long
Dim text As String
Dim index As Long
Dim data As Variant
Dim rw As Long
ff = FreeFile
Open "C:\temp\demo4.csv" For Input As #ff
Do While Not EOF(ff)
Line Input #ff, text
data = Split(text, ",")
rw = rw + 1
For index = LBound(data, 1) To UBound(data, 1)
With Cells(rw, index + 1)
.NumberFormat = "@"
.Value = data(index)
End With
Next
Loop
End Sub
"Alan" wrote in message
...
I have a macro that opens a CSV file. The problem is that it
recognizes text fields containing slashes as dates, which I do not
want.
I have searched for a solution with Google, but none of them seem to
work. I tried from the Excel menu importing CSV files as external
data using General and then Text format, but this did not work. I
tried changing the file extension to .vcs or .txt and then importing.
This did not work with either General nor Text form.
Can anyone tell me how to get around this problem?
I am using Excel 2003. I also have 2007.
Thanks, Alan
|