By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,164 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,164 IT Pros & Developers. It's quick & easy.

giving name to new file

100+
P: 553
Hi
I am opening a file (creating new one at same time)

Expand|Select|Wrap|Line Numbers
  1.   LogFileName = "C:\" & "logfile" & Now() & ".txt"
  2.  
but the above code is not good for
Expand|Select|Wrap|Line Numbers
  1. Open LogFileName For Append As #FileNum
  2.  
because i am doing Now() thing with file name and path.

Therefore i get Path Not found error:

Is there any way to add current Date and time with file name when creating a new file ?

Thanks
Aug 10 '07 #1
Share this Question
Share on Google+
1 Reply


P: 47
The problem is that Now() by default returns the date and time in the format

dd/mm/yy hh:mm:ss

You can't have multiple colons in path names and the forward slashes are interpreted as directory separators - in this case for directories which don't exist.

Try this instead:
<code> vb
LogFileName = "C:\" & "logfile" & format(Now(),"dd-mm-yy") & ".txt"
</code>

which will create a file named C:\logfile10-08-07.txt, which is what I think you want
Aug 10 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.