Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to enter a Date string into this peice of code

Status
Not open for further replies.

JamesFlowers

Programmer
Mar 23, 2001
97
GB
Hi,

I am creating a macro to automatically save the workbook to a file with the sysdate and time.

Here is the code

ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\james_f\Desktop\Product List Requests Sheet.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

Our point for doing this to create a unique file each time it is run and to be saved for client distribution and then historical reference.

Many Thanks

James Flowers James Flowers
 
Do you want the date and time in the document name? Perhaps this will work for you:

dim sNow as string

sNow = format(Now(), "dd-mm-yyyy hh mmAM/PM")
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\james_f\Desktop\Product List Requests Sheet " & sNow & ".xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
 
And if you also want them to sort properly in alpha order, you might try
sNow=format(Now(), "yyyy-mm-dd Hh-mm")

Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top