Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Incorrect date format when opening txt or csv files via macro

I refer to other posts on the same topic
Subject: importing a text file - problem with dates "Americanising"
2/21/2006 9:47 AM PST
Subject: opening text file in excel problem 2/10/2006 6:42 AM PST

Neither of the above seem to be actually answered satisfactorily.

My issue is the same

When I open a text file with a .csv or .txt extension in Excel 2003 - date
data appears correctly as expected.

However when I do it via simple macro - the american date format is invoked
and I get incorrect dates

e.g source data in .txt or .csv file

Field 1,Date,Field 3,Field 4
text,10/03/2006 08:04,text,text '( 10 March
2006)

Either of the following macros has the same result


Sub Test()
Workbooks.Open Filename:="test2.csv"
End Sub


Sub TestTxt()
Workbooks.OpenText Filename:="Test2.txt", _
Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False,
Semicolon:=False _
, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1,
1), _
Array(2, 4), Array(3, 1), Array(4, 1)), TrailingMinusNumbers:=True
Range("B2").Select
End Sub

The date now appears as follows

Field 1 Date Field 3 Field 4
text 03/10/2006 08:04 text text

I did not have this problem with Excel 2000.

Any explanations or automated workarounds would be appreciated

--
P Roberts
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Incorrect date format when opening txt or csv files via macro

If you have renamed the file to have a ".txt" extension as you example shows,
then opentext should work.

If you leave it with a .csv extension, then your settings will be ignored
using Opentext.

--
Regards,
Tom Ogilvy


"proberts" wrote:

I refer to other posts on the same topic
Subject: importing a text file - problem with dates "Americanising"
2/21/2006 9:47 AM PST
Subject: opening text file in excel problem 2/10/2006 6:42 AM PST

Neither of the above seem to be actually answered satisfactorily.

My issue is the same

When I open a text file with a .csv or .txt extension in Excel 2003 - date
data appears correctly as expected.

However when I do it via simple macro - the american date format is invoked
and I get incorrect dates

e.g source data in .txt or .csv file

Field 1,Date,Field 3,Field 4
text,10/03/2006 08:04,text,text '( 10 March
2006)

Either of the following macros has the same result


Sub Test()
Workbooks.Open Filename:="test2.csv"
End Sub


Sub TestTxt()
Workbooks.OpenText Filename:="Test2.txt", _
Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False,
Semicolon:=False _
, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1,
1), _
Array(2, 4), Array(3, 1), Array(4, 1)), TrailingMinusNumbers:=True
Range("B2").Select
End Sub

The date now appears as follows

Field 1 Date Field 3 Field 4
text 03/10/2006 08:04 text text

I did not have this problem with Excel 2000.

Any explanations or automated workarounds would be appreciated

--
P Roberts

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to reset incorrect date format after reinstalation of Window X ml Setting up and Configuration of Excel 3 May 7th 08 10:34 PM
Date Format incorrect [email protected] Excel Discussion (Misc queries) 0 March 29th 07 06:16 PM
incorrect Format Date mm/yyyy in excel 2003 paracio Excel Programming 0 September 7th 05 02:54 AM
day/month/year in incorrect format for date format M&A_Jack Excel Worksheet Functions 2 August 16th 05 08:15 PM
Incorrect date format Ric[_4_] Excel Programming 4 July 15th 04 11:34 AM


All times are GMT +1. The time now is 05:32 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"