PC Review


Reply
Thread Tools Rate Thread

Code to convert date (xx/xx/xx) to xx xx xx

 
 
Corey
Guest
Posts: n/a
 
      3rd Nov 2006
I need to use a date value in a cell as a workbook name, but have run into
problems as, although i have changed the appearance of the date to a :
31 October 2006 value, rather than a 31/10/06.
a '/' is not a valid character for a file name, and therefore error's.

But even though the cell value (31 October 2006) does not have any '/'
(Slashes) in it, when i try to use the value as a workbook name, it still
grabs the date in a 31/10/06 format.

Therefore, is there a code i can change this date to a 31 10 06, with
Day,Month,Year separated by a single space?





Regards

Corey


 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      3rd Nov 2006
Corey,
Use Format. e.g.

Dim WBName as string
WBName=Format(Range("A1").Value,"dd-MMMM-YYYY")
'Or whatever style you want the date appear in

NickHK

"Corey" <(E-Mail Removed)> wrote in message
news:eN7jhwv$(E-Mail Removed)...
> I need to use a date value in a cell as a workbook name, but have run into
> problems as, although i have changed the appearance of the date to a :
> 31 October 2006 value, rather than a 31/10/06.
> a '/' is not a valid character for a file name, and therefore error's.
>
> But even though the cell value (31 October 2006) does not have any '/'
> (Slashes) in it, when i try to use the value as a workbook name, it still
> grabs the date in a 31/10/06 format.
>
> Therefore, is there a code i can change this date to a 31 10 06, with
> Day,Month,Year separated by a single space?
>
>
>
>
>
> Regards
>
> Corey
>
>



 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      3rd Nov 2006
whatever your date is, you can use replace:

dtstr = Replace(Date, "/", "")

or

dtstr = Format(Date, "yyyymmdd")

--


Gary


"Corey" <(E-Mail Removed)> wrote in message
news:eN7jhwv$(E-Mail Removed)...
>I need to use a date value in a cell as a workbook name, but have run into
>problems as, although i have changed the appearance of the date to a :
> 31 October 2006 value, rather than a 31/10/06.
> a '/' is not a valid character for a file name, and therefore error's.
>
> But even though the cell value (31 October 2006) does not have any '/'
> (Slashes) in it, when i try to use the value as a workbook name, it still
> grabs the date in a 31/10/06 format.
>
> Therefore, is there a code i can change this date to a 31 10 06, with
> Day,Month,Year separated by a single space?
>
>
>
>
>
> Regards
>
> Corey
>



 
Reply With Quote
 
Corey
Guest
Posts: n/a
 
      3rd Nov 2006
Thank You for the replies, but i cannot seem to get the codes to work with
this:

ActiveWorkbook.SaveAs Filename:= _
"\\Office2\my documents\TS\" & Sheet1.Range("E2").Value & ".xls",
FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False


The Date Format is in the E2 cell.
--
Regards

Corey


 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      3rd Nov 2006
Corey,
What is the value of Sheet1.Range("E2").Value ?

There's not code showing how you are formatting the date.

NickHK

"Corey" <(E-Mail Removed)> wrote in message
news:eEPQn6v$(E-Mail Removed)...
> Thank You for the replies, but i cannot seem to get the codes to work with
> this:
>
> ActiveWorkbook.SaveAs Filename:= _
> "\\Office2\my documents\TS\" & Sheet1.Range("E2").Value & ".xls",
> FileFormat:=xlNormal, _
> Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
> CreateBackup:=False
>
>
> The Date Format is in the E2 cell.
> --
> Regards
>
> Corey
>
>



 
Reply With Quote
 
Corey
Guest
Posts: n/a
 
      3rd Nov 2006
"E2" Displays 31 October 2006,
but the formula bar displays 31/10/2006.

I have the cell formatted as a date value.

Is that what you mean?
Regards

Corey


 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      3rd Nov 2006
Corey,
There is a difference between
Range("E1").Value
and
Range("E1").Text

see what you get for :
Debug.print Range("E1").Text,Range("E1").Value

NickHK

"Corey" <(E-Mail Removed)> wrote in message
news:eLcxXLw$(E-Mail Removed)...
> "E2" Displays 31 October 2006,
> but the formula bar displays 31/10/2006.
>
> I have the cell formatted as a date value.
>
> Is that what you mean?
> Regards
>
> Corey
>
>



 
Reply With Quote
 
Corey
Guest
Posts: n/a
 
      3rd Nov 2006
Ok, i now understand a bit more.

I changed the .value to .text and now i get the 31 October 2006 file name.

Thank You for your assistance Nick.

-
Regards

Corey


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Convert a yyyymmdd date format in code Claus Busch Microsoft Excel Programming 0 6th May 2011 08:01 AM
Linq to XML--Are there code examples that make Linq as easy as SQL? Or how can I convert ths simple pseudo code into real code? Reece Microsoft C# .NET 4 10th Dec 2008 03:13 AM
Convert a julian gregorian date code into a regular date =?Utf-8?B?Um9iZXJ0?= Microsoft Excel Worksheet Functions 3 13th Jun 2006 07:03 PM
code to convert date from TEXT format (03-02) to DATE format (200203) Gauthier Microsoft Excel Programming 0 22nd Sep 2004 03:26 PM
how to convert VBA #date# format to C# code? Rock Microsoft C# .NET 2 7th Mar 2004 11:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:18 PM.