View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
undrline via OfficeKB.com undrline via OfficeKB.com is offline
external usenet poster
 
Posts: 18
Default VBA to Fix Dates

Here is my attempt at using SendKeys:

Selection.NumberFormat = "m/d/yyyy"
SendKeys "%o", True ' Format
SendKeys "e", True ' Cells...
' Here's where it gets stuck:
' First, have to hope that the "Numbers" tab is the one showing
' Second, it stops with the dialog open, doesn't tab to the selected entry.
' And, if I try to complete the operation manually, it continues, tab and all,
after I select OK to the dialog.
SendKeys "{TAB}", True
SendKeys "c", True ' date format from previous line; only one C needs to
be pressed
SendKeys "{TAB}", True
SendKeys "m/d/yyyy", True
SendKeys "{TAB}", True
SendKeys "{TAB}", True
SendKeys "{TAB}", True
SendKeys "{ENTER}", True


undrline wrote:
I found the problem. Help me fix it, please . . .

It seems that the date format, becomes dependent on the regional settings (
http://write-me.org/screenshots/ShortDateFormat.gif). I think it
automatically interprets it as "Short Date Format" when I really want a
custom date format. I change the settings, and it changes the date format,
even while I have the document open. I think that manually choosing
FormatCells... and telling it Custom makes it understand that I want Custom
instead of ShortDate, whereas Selection.NumberFormat = "m/d/yyyy" doesn't.

So, I end up with a document that could appear appear differently when it is
sent to others! That's no good. I need something instead of Selection.
NumberFormat = "m/d/yyyy"

Thank you.

If you take my example, select the cells, and run the script, you'll see that
they don't change - 0#/0#/####

[quoted text clipped - 16 lines]

Matt


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200705/1