Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Automating Import of Date Information

Dear All,

Help would be gratefully received for the following:

I want to import data from a csv file.
When I do this manually (using File - Open - Text Import Wizard etc)
the date data comes in fine.
When I automate the process (by recording my manual actions and playing
the recorded macro) the date data is corrupted.

If you want to try it out then:
1) Save the following lines in a txt file. (note the dates are in
dd/mm/yyyy hh:mm format)
"User","Issue","Date"
"Andrew","a","10/01/2006 00:00:00"
"Andrew","b","31/01/2006 00:00:00"
"Andrew","c","11/02/2006 00:00:00"

2)
Record a macro opening the text file in Excel, comma-delimited, with "
as the text qualifier.

Sub Macro3()
'
' Macro3 Macro
' Macro recorded 23/05/2006 by Andrew Cox
'

'
Workbooks.OpenText Filename:= _
"C:\Apps\test.txt", Origin:= _
xlWindows, 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, 1), Array(3, 1))
Columns("C:C").EntireColumn.AutoFit
Range("C2:C4").Select
Selection.NumberFormat = "d-mmm"
End Sub

3) When you record the macro I think you will get the following dates
appearing:
10-Jan
31-Jan
11-Feb

4) But, when you play the macro (after closing the file), I think you
will get (like me!):
01-Oct
31/01/2006 00:00:00
02-Nov

Clearly, I'd like the first result rather than the second.

Any ideas how to correct this would be very welcome.

Thanks,

Andrew

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Automating Import of Date Information

You need to change the extension of the file from CSV to TXT. When it is
named CSV, excel ignores your settings in the OpenText method.

--
Regards,
Tom Ogilvy


"Andrew" wrote:

Dear All,

Help would be gratefully received for the following:

I want to import data from a csv file.
When I do this manually (using File - Open - Text Import Wizard etc)
the date data comes in fine.
When I automate the process (by recording my manual actions and playing
the recorded macro) the date data is corrupted.

If you want to try it out then:
1) Save the following lines in a txt file. (note the dates are in
dd/mm/yyyy hh:mm format)
"User","Issue","Date"
"Andrew","a","10/01/2006 00:00:00"
"Andrew","b","31/01/2006 00:00:00"
"Andrew","c","11/02/2006 00:00:00"

2)
Record a macro opening the text file in Excel, comma-delimited, with "
as the text qualifier.

Sub Macro3()
'
' Macro3 Macro
' Macro recorded 23/05/2006 by Andrew Cox
'

'
Workbooks.OpenText Filename:= _
"C:\Apps\test.txt", Origin:= _
xlWindows, 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, 1), Array(3, 1))
Columns("C:C").EntireColumn.AutoFit
Range("C2:C4").Select
Selection.NumberFormat = "d-mmm"
End Sub

3) When you record the macro I think you will get the following dates
appearing:
10-Jan
31-Jan
11-Feb

4) But, when you play the macro (after closing the file), I think you
will get (like me!):
01-Oct
31/01/2006 00:00:00
02-Nov

Clearly, I'd like the first result rather than the second.

Any ideas how to correct this would be very welcome.

Thanks,

Andrew


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Automating Import of Date Information

Tom,

Thanks for the reply, but at the moment the file already has a .txt
extension (see the macro code created).

Apologies if speaking of the file as a CSV lead to the confusion.

Thanks,

Andrew

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
Automating Address Information based on selecting data via a validation list BrownsFan Excel Worksheet Functions 2 January 11th 07 10:09 PM
XIRR - Automating the date range WTM Excel Discussion (Misc queries) 0 November 2nd 06 06:49 PM
Automating import of Word tables into Excel Han Excel Discussion (Misc queries) 0 January 18th 06 08:42 AM
Automating data import and separation Brad K. Excel Programming 3 July 5th 05 11:32 PM
Automating import of a certain type of 'txt' file Stuart[_5_] Excel Programming 1 February 12th 04 08:52 PM


All times are GMT +1. The time now is 11:22 PM.

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

About Us

"It's about Microsoft Excel"