Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Opening .CSV file

I have a .CSV file which i am opening through VBA code:

set wb = workbooks.open(Filepath)

When I open the file the first columns reads:

19/04/10
19/04/10
19/04/10

When I open the file via the file menu (File | Open) the first column reads:

19/04/2010
19/04/2010
19/04/2010

What do I have to do to be able to open the file via VBA and have the column
1 values seen as they appear when the file is opened normally?

PWS


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Opening .CSV file

When you use File|Open, excel will use your windows regional settings -- and you
have your date format set to dmy.

But when VBA opens the file, it doesn't use your regional setting. It's USA
centric and uses an mdy order.

And since 19/04/10 doesn't look like a date in mdy order, excel will treat it as
text.

You may have noticed that some data comes in ok. But it's not!

It may look like it's a date, but it's not the date that the CSV file wants.

05/06/10 would come in as May 6, 2010 -- not June 6, 2010 (what the data really
meant).

So don't just try to fix the data after importing it.

Instead, rename/copy the .CSV file to .TXT. And then record a macro when you
open that file manually. Excel will show you the text to columns wizard and
you'll be able to specify that field as a date (dmy order).

Then incorporate that recorded code into your existing macro.

But you'll have to rename/copy that CSV file (either manually or via code)
before this modified code runs.





Paul W Smith wrote:

I have a .CSV file which i am opening through VBA code:

set wb = workbooks.open(Filepath)

When I open the file the first columns reads:

19/04/10
19/04/10
19/04/10

When I open the file via the file menu (File | Open) the first column reads:

19/04/2010
19/04/2010
19/04/2010

What do I have to do to be able to open the file via VBA and have the column
1 values seen as they appear when the file is opened normally?

PWS


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Opening .CSV file

Or I could just add the Local= TRUE :

set wb = workbooks.open(FileName:=Filepath, Local:=True)

I answer my own question in case away seaches my original question and wants
another solution.



"Dave Peterson" wrote in message
...
When you use File|Open, excel will use your windows regional settings --
and you
have your date format set to dmy.

But when VBA opens the file, it doesn't use your regional setting. It's
USA
centric and uses an mdy order.

And since 19/04/10 doesn't look like a date in mdy order, excel will treat
it as
text.

You may have noticed that some data comes in ok. But it's not!

It may look like it's a date, but it's not the date that the CSV file
wants.

05/06/10 would come in as May 6, 2010 -- not June 6, 2010 (what the data
really
meant).

So don't just try to fix the data after importing it.

Instead, rename/copy the .CSV file to .TXT. And then record a macro when
you
open that file manually. Excel will show you the text to columns wizard
and
you'll be able to specify that field as a date (dmy order).

Then incorporate that recorded code into your existing macro.

But you'll have to rename/copy that CSV file (either manually or via code)
before this modified code runs.





Paul W Smith wrote:

I have a .CSV file which i am opening through VBA code:

set wb = workbooks.open(Filepath)

When I open the file the first columns reads:

19/04/10
19/04/10
19/04/10

When I open the file via the file menu (File | Open) the first column
reads:

19/04/2010
19/04/2010
19/04/2010

What do I have to do to be able to open the file via VBA and have the
column
1 values seen as they appear when the file is opened normally?

PWS


--

Dave Peterson



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Opening .CSV file

That'll depend on what versions of excel you're supporting.


Paul W Smith wrote:

Or I could just add the Local= TRUE :

set wb = workbooks.open(FileName:=Filepath, Local:=True)

I answer my own question in case away seaches my original question and wants
another solution.

"Dave Peterson" wrote in message
...
When you use File|Open, excel will use your windows regional settings --
and you
have your date format set to dmy.

But when VBA opens the file, it doesn't use your regional setting. It's
USA
centric and uses an mdy order.

And since 19/04/10 doesn't look like a date in mdy order, excel will treat
it as
text.

You may have noticed that some data comes in ok. But it's not!

It may look like it's a date, but it's not the date that the CSV file
wants.

05/06/10 would come in as May 6, 2010 -- not June 6, 2010 (what the data
really
meant).

So don't just try to fix the data after importing it.

Instead, rename/copy the .CSV file to .TXT. And then record a macro when
you
open that file manually. Excel will show you the text to columns wizard
and
you'll be able to specify that field as a date (dmy order).

Then incorporate that recorded code into your existing macro.

But you'll have to rename/copy that CSV file (either manually or via code)
before this modified code runs.





Paul W Smith wrote:

I have a .CSV file which i am opening through VBA code:

set wb = workbooks.open(Filepath)

When I open the file the first columns reads:

19/04/10
19/04/10
19/04/10

When I open the file via the file menu (File | Open) the first column
reads:

19/04/2010
19/04/2010
19/04/2010

What do I have to do to be able to open the file via VBA and have the
column
1 values seen as they appear when the file is opened normally?

PWS


--

Dave Peterson


--

Dave Peterson
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
Macro for Opening Reuters, Opening Excel File, Closing Excel File Tsp245 Excel Programming 2 August 14th 08 07:24 PM
opening a file in Excel starts application but dose not open file Bob Shelton Excel Discussion (Misc queries) 1 July 2nd 08 07:51 PM
File:1 and File:2 -- Double Files when Opening One File dallin Excel Discussion (Misc queries) 1 January 25th 07 02:53 AM
opening an excel file opens a duplicate file of the same file skm Excel Discussion (Misc queries) 1 December 7th 05 05:52 PM
Error:Invalid File format,while opening an Excel Template file Saurabh Excel Programming 1 January 17th 05 07:15 AM


All times are GMT +1. The time now is 02:09 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"