Sub saveas()
Dim wName As String
[COLOR=#008000]'Name of the workbook : replace A1 by the date Cell and format as wished. If today's date, the file here would be named 14.12.2018[/COLOR]
wName = Format(Range("[COLOR=#ff0000]A1[/COLOR]").Value, "[COLOR=#ff0000]dd.mm.yyyy[/COLOR]")
Dim wPath
[COLOR=#008000]'Define the folder[/COLOR]
wPath = "C:\[COLOR=#ff0000]8[/COLOR]\"
ThisWorkbook.saveas Filename:=wPath & wName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
End Sub
Code:Sub saveas() Dim wName As String [COLOR=#008000]'Name of the workbook : replace A1 by the date Cell and format as wished. If today's date, the file here would be named 14.12.2018[/COLOR] wName = Format(Range("[COLOR=#ff0000]A1[/COLOR]").Value, "[COLOR=#ff0000]dd.mm.yyyy[/COLOR]") Dim wPath [COLOR=#008000]'Define the folder[/COLOR] wPath = "C:\[COLOR=#ff0000]8[/COLOR]\" ThisWorkbook.saveas Filename:=wPath & wName, FileFormat:=xlOpenXMLWorkbookMacroEnabled End Sub
Sub Test_File_Exist_With_Dir()
Dim wName As String
Dim FilePath As String
Dim counter As Long
Dim counter2 As Long
Dim success As Long
counter = 1
counter2 = 1
success = 0
wName = Format(Range("A1").Value, "dd-mm-yyyy")
wPath = [COLOR=#333333]"C:\[/COLOR][COLOR=#ff0000]8[/COLOR][COLOR=#333333]\"[/COLOR]
Do Until success = 1
Application.ScreenUpdating = False
FilePath = ""
On Error Resume Next
FilePath = Dir(wPath & wName & ".xlsm")
On Error GoTo 0
If FilePath = "" Then
ThisWorkbook.saveas Filename:=wPath & wName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
success = 1
Else
wName = Format(Range("A1").Value, "dd-mm-yyyy") & "(" & counter & ")"
If counter2 <> 1 Then
counter = counter + 1
End If
counter2 = counter2 + 1
End If
Loop
Application.ScreenUpdating = False
End Sub