Excel Automation - Problems with strings containing dates

jump-jet

New Member
Joined
Jul 13, 2011
Messages
3
64-bit Windows7, Excel 2007

I'm driving Excel from within a .NET program using Excel's automation interface. I'm running on a PC in England, where the date format is "dd/mm/yyyy".

When I insert a string containing "10/05/2011" (10th May 2011) into a cell and then view the cell in Excel, Excel shows "05/10/2011" in the cell, and the date has become 5th October 2011 (in other words if I use the "Format Cells" operation on the cell, the Category shown is Date, the Sample value represented is the fifth of October and the Locale is shown as English (UK)).

Correct me if I'm wrong, but it looks to me as if the Excel automation interface has inspected the string and recognised it as a date, but has not using the expected locale when it then parsed the date. How can I control the locale used by the automation interface?

Dave
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Change thread's Culture to UK.
Code:
Imports System.Threading
Imports System.Globalization

Thread.CurrentThread.CurrentCulture = New CultureInfo("en-GB")
 
Upvote 0
So, which notation you need?

I don't understand your question.
I need to be able to take a date string that was formatted using the PC's current locale (e.g. for 10th May 2011 on an English PC "10/05/2011", or "05/10/2011" on a US PC) and import it into Excel using automation so that the date in Excel is correctly set to 10th May 2011.
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,917
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top