20/01/2020, 11:47
accessman
Kod:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim sOldName As String
    'If SaveAsUI Then
        Cancel = True 'cancel the save and do it yourself in code
        sOldName = Me.FullName 'store the old name so you can delete it later
        'Save using the value in the cell
        Application.EnableEvents = False
            Me.SaveAs Me.Path & Application.PathSeparator & _
                Me.Worksheets("CUST").Range("FILE").Value & ".xls"
        Application.EnableEvents = True
        'If the name changed, delete the old file
        If Me.FullName <> sOldName Then
            On Error Resume Next
                Kill sOldName
            On Error GoTo 0
        End If
    'End If
End Sub