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
 

btadams

Well-known Member
Joined
Jan 6, 2003
Messages
1,928
try this:

Code:
Public Sub SaveAsD63()
    ThisFile = CurDir & "\" & Range("D63").Value & Replace(Date, "/", "-")
    ActiveWorkbook.SaveAs Filename:=ThisFile
End Sub
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,288
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.
 

paulie123

New Member
Joined
Nov 20, 2005
Messages
6
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
 

btadams

Well-known Member
Joined
Jan 6, 2003
Messages
1,928
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
 

Forum statistics

Threads
1,078,431
Messages
5,340,211
Members
399,360
Latest member
HDavid21

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top