Hi all,
I'm running a piece of vba code that opens a save as box and autofill's the filename. The vba references two cells to create the filename, one of these cells (C6) being the date. The date cell is filled in by the user of the form and may not be the current days date.
The cell format has been set to show the date as 26-07-23 for example but if the user enters the date in the format of 26/07/23 for example, the formatting of the cell corrects it to 26-07-23 but when the save as box opens, it shows it as what the user entered, 26/0723. This then causes windows to refuse to save the workbook.
Is there any way around this? The date of the cell isn't always the current day otherwise I could code the vba to show this.
Thank you all
I'm running a piece of vba code that opens a save as box and autofill's the filename. The vba references two cells to create the filename, one of these cells (C6) being the date. The date cell is filled in by the user of the form and may not be the current days date.
The cell format has been set to show the date as 26-07-23 for example but if the user enters the date in the format of 26/07/23 for example, the formatting of the cell corrects it to 26-07-23 but when the save as box opens, it shows it as what the user entered, 26/0723. This then causes windows to refuse to save the workbook.
Is there any way around this? The date of the cell isn't always the current day otherwise I could code the vba to show this.
Thank you all
VBA Code:
Sub SaveFile()
Dim NameFile As Variant
With Worksheets("Form")
NameFile = .Range("C2") & " - " & .Range("C6") & ".xlsm"
End With
NameFile = Application.GetSaveAsFilename(InitialFileName:=NameFile, Filefilter:="Excel Workbook (*.xlsm), *.xlsm")
If NameFile = False Then
MsgBox "File Not Saved"
Else
ThisWorkbook.SaveAs Filename:=NameFile
End If
End Sub