Save with current date

paulie123

New Member
Joined
Nov 20, 2005
Messages
6
Hi,

I'm using the following macro to save a workbook file;

Public Sub SaveAsD63()
ThisFile = Range("D63").Value
ActiveWorkbook.SaveAs Filename:=ThisFile
End Sub

1. How can this be modified to add the current date, (DD/MM/YYYY) to the filename,
2.How can i save the file to the current directory

Thanks in advance for your help
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
try this:

Code:
Public Sub SaveAsD63()
    ThisFile = CurDir & "\" & Range("D63").Value & Replace(Date, "/", "-")
    ActiveWorkbook.SaveAs Filename:=ThisFile
End Sub
 
Upvote 0
Is this any use?
Code:
Public Sub SaveAsD63()
ThisFile = Range("D63").Value
ActiveWorkbook.SaveAs CurDir & "\" & ThisFile & Format(Date, "ddmmyyyy")
End Sub
By the way you can't have the / in a filename.
 
Upvote 0
thanks, that's solved one half of my problem!! the template file is in a folder on my desktop, but the file saves to the my documents folder. I need to save to the same folder as the template.

Thanks
 
Upvote 0
Try this:

Code:
Public Sub SaveAsD63()
Dim ThisFile As String

    On Error GoTo errhandler
    ThisFile = "C:\Documents and Settings\<username>\Desktop\<MyFolder>\"
    ThisFile = ThisFile & Range("D63").Value & Replace(Date, "/", "-")
    ActiveWorkbook.SaveAs Filename:=ThisFile
    Exit Sub
errhandler:
    MsgBox "An error occurred. Could not save the file:" & vbCrLf & vbCrLf & ThisFile, vbCritical + vbOKOnly
    On Error GoTo 0
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,516
Messages
6,119,981
Members
448,934
Latest member
audette89

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top