LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default DateTime format

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)


 
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
Datetime CSV format kh[_2_] Excel Discussion (Misc queries) 1 November 13th 08 09:08 AM
DateTime datatype in VBA Alex Excel Programming 4 January 30th 07 06:36 PM
Custom DateTime Format Sam Excel Programming 1 May 1st 06 08:34 PM
datetime format issues when linking access to excel Season Excel Discussion (Misc queries) 0 December 6th 05 04:52 PM
DateTime Format Joe Harriman Excel Programming 1 October 3rd 03 02:57 PM


All times are GMT +1. The time now is 07:42 AM.

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

About Us

"It's about Microsoft Excel"