View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
joeu2004[_2_] joeu2004[_2_] is offline
external usenet poster
 
Posts: 829
Default Date format/value different when opening manually compare to VBA macro

"colmkav" wrote:
when I run my macro today the dates in my file appear
as 08/07/2012 when I open via the following VBA statement:

[....]
sBalanceName = "C:\temp\Balance.csv"
Set wbBalance = Workbooks.Open(sBalanceName)

[....]
However, if I open manually in Excel the dates appear as
07/08/2012. How can I solve this problem?


I cannot duplicate this behavior.

Note that a CSV is simply ASCII text that Excel interprets each time as if
you entered the contents manually. So Excel will interpret 8/7/2012
according to the short-date form that is set in the Regional and Language
Options control panel. And that will be the default display format.

(But I vaguely and perhaps incorrectly recall that VBA has its own fixed
format. TBD.)

So the questions that come to mind a
1. How does the date appear when you open the CSV file in Notepad?
2. How are you seeing the date after the Workbooks.Open statement? Are you
looking at the worksheet in Excel? Or are you looking at it in VBA; if so,
how: MsgBox, Debug.Print, Format, something else?
3. Are you seeing the different appearances of the date on the same
computer?

Can you upload example CSV and Excel files (devoid of any private data) that
demonstrates the problem to a file-sharing website? Post the "shared",
"public" or "view-only" link (aka URL; http://...) in a response here. The
following is a list of some free file-sharing websites; or use your own.

Box.Net: http://www.box.net/files
Windows Live Skydrive: http://skydrive.live.com
MediaFi http://www.mediafire.com
FileFactory: http://www.filefactory.com
FileSavr: http://www.filesavr.com
FileDropper: http://www.filedropper.com
RapidSha http://www.rapidshare.com