Code to add current date and time

ro801

Registered User.
Local time
Today, 15:56
Joined
Apr 12, 2012
Messages
24
Hi
I'm currently using:
Dim pStr As String
pStr = "S:\ChestPain\Elective Cardioversion\Correspondence\"
pStr = pStr + ActiveDocument.Bookmarks("DCCVUN").Range.Text
pStr = pStr + "-"
pStr = pStr + ActiveDocument.Bookmarks("CASE").Range.Text
pStr = pStr + "-AFOpClinic"
at the end of a macro to save the newly opened file to a specific location and as a specific format. Problem is that i may need to perform the same action again but would require a new document called something else unique. Is there a way of adding the current date and time to filename too, so i always have a different filename? If not, can anyone suggest how i would otherwise create an always unique filename?
Many Thanks
 
Hi,

Yes, you can use the function Now() to return the date/time. I have used the format function here to return the date/time in the format yyyymmdd hhnnss. Note that hhnnss is the time in hours, minutes and seconds.

Code:
Dim pStr As String
pStr = "S:\ChestPain\Elective Cardioversion\Correspondence\"
pStr = pStr + ActiveDocument.Bookmarks("DCCVUN").Range.Text
pStr = pStr + "-"
pStr = pStr + ActiveDocument.Bookmarks("CASE").Range.Text
pStr = pStr + "-AFOpClinic"
pStr = pStr & format(now(),"yyyymmdd_hhnnss")
 
Fab thank you; you've saved my bacon!!
 

Users who are viewing this thread

Back
Top Bottom