ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   changing the date separator (https://www.excelbanter.com/excel-programming/354082-changing-date-separator.html)

Johnny Mick

changing the date separator
 
I have to save a file using 'todays' date in the filename. I had to change
my system settings in order for the macro to work on my desktop. Runs
properly. I am being moved into a different position, and now someone else
is going to be having to run this macro. Is there a way to programmatically
change the date format (so that it uses a ' - ' separator, instead of the ' /
' default)? It would be nice to not have to change everyone's system
settings, just so they can run my macro. Oh yeah, beginner/novice excel
macro writer, so this is probably an easy one to answer. Thanks in advance
for any assistance.

Dave Peterson

changing the date separator
 
You can use a string variable to hold a nicely formatted data:

dim myDateStr as string
mydatestr = format(date,"mm-dd-yyyy")

or whatever mdy, dmy, ydm, ... format you want.

Johnny Mick wrote:

I have to save a file using 'todays' date in the filename. I had to change
my system settings in order for the macro to work on my desktop. Runs
properly. I am being moved into a different position, and now someone else
is going to be having to run this macro. Is there a way to programmatically
change the date format (so that it uses a ' - ' separator, instead of the ' /
' default)? It would be nice to not have to change everyone's system
settings, just so they can run my macro. Oh yeah, beginner/novice excel
macro writer, so this is probably an easy one to answer. Thanks in advance
for any assistance.


--

Dave Peterson

Johnny Mick[_2_]

changing the date separator
 
Thanks Dave. I figured it had to be something simple, and I just couldn't
figure it out using my little macro book. Works like a charm.

"Dave Peterson" wrote:

You can use a string variable to hold a nicely formatted data:

dim myDateStr as string
mydatestr = format(date,"mm-dd-yyyy")

or whatever mdy, dmy, ydm, ... format you want.

Johnny Mick wrote:

I have to save a file using 'todays' date in the filename. I had to change
my system settings in order for the macro to work on my desktop. Runs
properly. I am being moved into a different position, and now someone else
is going to be having to run this macro. Is there a way to programmatically
change the date format (so that it uses a ' - ' separator, instead of the ' /
' default)? It would be nice to not have to change everyone's system
settings, just so they can run my macro. Oh yeah, beginner/novice excel
macro writer, so this is probably an easy one to answer. Thanks in advance
for any assistance.


--

Dave Peterson



All times are GMT +1. The time now is 10:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com