Trouble with OpenText() and Date/Time Values

R

rmac

Hello,

I want to import a CSV into an Excel worksheet. Each line of the
CSV file contains three integers and a date/time value in
mm/dd/yyyy hh:mm:ss format. Here are a few lines from the actual
CSV file:

1,101,26,3/19/2006 13:02:00
2,102,27,3/19/2006 13:02:10
3,103,28,3/19/2006 13:02:20
4,104,29,3/19/2006 13:02:30
5,105,30,3/19/2006 13:02:40
6,106,31,3/19/2006 13:02:50

If I open this file using the normal File->Open command,
everything works fine. However, when I try to open it using the
OpenText() method, the "seconds" part of the time values gets
dropped and all the time values end up the same in the worksheet
(13:02:00 for the data in the example above).

(I know that you have to change the cell formatting from the
default in order to see the "seconds" part of the date/time
values.)

The code that I'm using follows. What can I do to get OpenText()
to correctly read the "seconds" part of my time values?

Thanks,

-- Russ Cooper

------------------------------------------------------------------

On Error GoTo RawDataProblem
Workbooks.OpenText (RawFilename.Text) ' Raw data -> temp workbook
On Error GoTo 0
ActiveSheet.UsedRange.Select ' Select raw data
Selection.Copy ' Copy raw data to clipboard
ActiveWorkbook.Close ' Close the temporary workbook

On Error Resume Next ' Error handling off for now
Set TargetSheet = Worksheets("Raw") ' Try to access Raw worksheet
On Error GoTo 0 ' Resume normal error handling
If Not TargetSheet Is Nothing Then ' If Raw worksheet exists,
Worksheets("Raw").Delete ' delete it
End If ' End "Raw worksheet exists"

Set NewSheet = Worksheets.Add ' Make a new worksheet
NewSheet.name = "Raw"
Worksheets("Raw").Range("A1").Select ' Paste raw data here
Worksheets("Raw").Paste ' Do the pasting
 

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