Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 276
Default Code to convert date (xx/xx/xx) to xx xx xx

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Code to convert date (xx/xx/xx) to xx xx xx

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" wrote in message
...
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Code to convert date (xx/xx/xx) to xx xx xx

whatever your date is, you can use replace:

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

or

dtstr = Format(Date, "yyyymmdd")

--


Gary


"Corey" wrote in message
...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 276
Default Code to convert date (xx/xx/xx) to xx xx xx

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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Code to convert date (xx/xx/xx) to xx xx xx

Corey,
What is the value of Sheet1.Range("E2").Value ?

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

NickHK

"Corey" wrote in message
...
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






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 276
Default Code to convert date (xx/xx/xx) to xx xx xx

"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


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Code to convert date (xx/xx/xx) to xx xx xx

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" wrote in message
...
"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




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 276
Default Code to convert date (xx/xx/xx) to xx xx xx

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert Gregorian date into Hijri Date in Excel 2007? Ahmed Excel Discussion (Misc queries) 2 February 6th 09 03:59 PM
Convert a Number Code to a Text Code Traye Excel Discussion (Misc queries) 3 April 6th 07 09:54 PM
Excel code convert to Access code - Concat & eliminate duplicates italia Excel Programming 1 September 12th 06 12:14 AM
Convert a julian gregorian date code into a regular date Robert Excel Worksheet Functions 3 June 13th 06 07:03 PM
code to convert date from TEXT format (03-02) to DATE format (200203) Gauthier[_2_] Excel Programming 0 September 22nd 04 03:26 PM


All times are GMT +1. The time now is 12:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"