Format of Date - Saveas Issue

trevolly

Board Regular
Joined
Aug 22, 2021
Messages
120
Office Version
  1. 365
Platform
  1. Windows
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

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
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Try changing this line:
VBA Code:
NameFile = .Range("C2") & " - " & .Range("C6") & ".xlsm"
to:
VBA Code:
NameFile = .Range("C2") & " - " & Format(.Range("C6"),"dd-mm-yy") & ".xlsm"
 
Upvote 1
Hi
try using the Range.TEXT property

Rich (BB code):
NameFile = .Range("C2").Text & " - " & .Range("C6").Text & ".xlsm"

and see if resolves your issue

Dave
 
Upvote 1
Solution

Forum statistics

Threads
1,215,136
Messages
6,123,246
Members
449,093
Latest member
Vincent Khandagale

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