+ Reply to Thread
Results 1 to 2 of 2

Force file name format

Hybrid View

Dude101 Force file name format 07-15-2008, 01:27 PM
mudraker You can use use... 07-16-2008, 08:50 AM
  1. #1
    Registered User
    Join Date
    07-15-2008
    Location
    Toronto
    Posts
    1

    Cool Force file name format

    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

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    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

    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 assisted or failed to assist you I welcome your Feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1