Hi all
Found this VBA code in the Internet (don’t remember where) is really great ... only it saves in .xlsx format.
What i need: each time I want to save or close the file, an exactly the same file (with all macros .. as a “saving as” command) should be created as a full backup of this file.
At the same time, is it possible to save the same code in .xlsm format?
.. and if possible automatically adds the date in the saved name?
Can someone help me? Thank you in advance
Found this VBA code in the Internet (don’t remember where) is really great ... only it saves in .xlsx format.
What i need: each time I want to save or close the file, an exactly the same file (with all macros .. as a “saving as” command) should be created as a full backup of this file.
At the same time, is it possible to save the same code in .xlsm format?
.. and if possible automatically adds the date in the saved name?
VBA Code:
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim WbZ As Workbook
Dim Pfad$, Dname$, Info
Pfad = "\\WDMYCLOUD\Team\0 Niko\PLANER\Planer 2020\Backup"
Dname = "Backup.xlsm"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
With Me
If Not .ReadOnly Then
Select Case .Saved
Case Is = False
Info = MsgBox("Die Mappe wurde noch nicht gespeichert." & vbLf & _
"Soll diese Mappe gespeichert werden?", vbYesNo, _
"Schließen und Speichern?")
'Wenn Mappe vor dem Schließen gespeichert wird,
'dann Sicherheitskopie
If Info = vbYes Then
.Save
.Sheets.Copy
Set WbZ = ActiveWorkbook
With WbZ
.SaveAs Filename:=Pfad & Dname, _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
.Close True
End With
.Close
'Wenn Mappe vor dem SChließen NICHT gespeichert wird,
'dann KEINE Sicherheitskopie
Else:
.Saved = True
.Close
End If
'Mappe wurde NICHT geändert oder bereits gespeichert
'Dann KEINE Sicherheitskopie
End Select
End If
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Can someone help me? Thank you in advance