Thread: DateTime format
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default DateTime format

You have two suggestions to use Format. For my curiosity could you confirm
they work correctly, in particular does the "yyyy" help provide the correct
year in your non English version. Just wondering if perhaps it should be
"jjjj", assuming jaar = year for you.

Regards,
Peter T

"Henk" wrote in message
...
I have the following code to open a csv file for writing. To make a unique
name for the file I make use of the Now() function. E.g. I get the file
name :

C:\HF\Excel\Work\Naam_20090320_130144.csv

However, when run on another machine with different date time setting it
could result in :

C:\HF\Excel\Work\Naam_-200Ma_1:0:4:3.csv

Which result in an error.

How can I make sure that I will always get the first result?


Code :

Dim ThisDirectory As String
ThisDirectory = ActiveWorkbook.Path
Dim TimeStamp As String
TimeStamp = Mid(Now(), 7, 4) & Mid(Now(), 4, 2) & Mid(Now(), 1, 2)
&
"_" & Mid(Now(), 12, 2) & Mid(Now(), 15, 2) & Mid(Now(), 18, 2)
Dim csvFileName As String
csvFileName = ThisDirectory & "\Naam_" & TimeStamp & ".csv"
Dim ReadyText As String

Set csvObject = CreateObject("Scripting.FileSystemObject")
Set csvFile = csvObject.CreateTextFile(csvFileName, True)