I want to be able to force the format of the naming of a file when someone does a "Save As"
i.e. the person must enter ####-mmdd (1137-0710) and if the format doesn't meet the convention format then a error message comes up until the name it right.
Does anyone know if there is a VBA that does this
Thanks![]()
You can use use GetSaveAsFilename to get the saveAs filename then test the result before saving
This will not give you exactly what you want
Testing for mmdd would take more coding
Code:Sub FileSaveAs() Dim sFile As String Dim sFname As String Dim bFnameTestFail As Boolean GetFileName: 'get path & filename sFile = Application.GetSaveAsFilename(fileFilter:="Excel Files (*.xls), *.xls") 'test for cancel button selection If sFile = "False" Then Exit Sub End If 'test file name If Not Len(sFname) = 13 Then MsgBox "Incorect file name format" End If If Not IsNumeric(Left(sFname, 4)) Then MsgBox "Incorect file name format" End If If Not Mid(sFname, 5, 1) = "-" Then MsgBox "Incorect file name format" End If If Not IsNumeric(Mid(sFname, 6, 4)) Then MsgBox "Incorect file name format" End If If bFnameTestFail = True Then MsgBox "Incorect file name format" GoTo GetFileName End If ActiveWorkbook.SaveAs Filename:=sFile End Sub
Please Read Forum Rules Before Posting
Wrap VBA code by selecting the code and clicking the # icon or Read This
How To Cross Post politely
Top Excel links for beginners to Experts
If you are pleased with a member's answer then use the Scales icon to rate it
If my reply has assistedor failed to assist you
I welcome your Feedback.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks