AccessTr.neT
Excel Dosyasını İsim Değiştirerek Kaydetmek - Baskı Önizleme

+- AccessTr.neT (https://accesstr.net)
+-- Forum: Microsoft Excel (https://accesstr.net/forum-microsoft-excel.html)
+--- Forum: Excel Örnekleri ve Uygulamaları (https://accesstr.net/forum-excel-ornekleri-ve-uygulamalari.html)
+--- Konu Başlığı: Excel Dosyasını İsim Değiştirerek Kaydetmek (/konu-excel-dosyasini-isim-degistirerek-kaydetmek.html)



Excel Dosyasını İsim Değiştirerek Kaydetmek - accessman - 20/01/2020

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