Onderstaande code (gevonden op dit forum) maakt een backup bij afsluiten. (backup op externe schijf G)
Tevens worden alle oude backups (behalve de laatste 3) verwijderd. werkt perfect:d
Is het ook mogelijk om deze code zo te schrijven dat er van de Bovenliggende Map een backup wordt gemaakt.?
	
	
	
	
		
				
			Tevens worden alle oude backups (behalve de laatste 3) verwijderd. werkt perfect:d
Is het ook mogelijk om deze code zo te schrijven dat er van de Bovenliggende Map een backup wordt gemaakt.?
		Code:
	
	Const sPad = "G:\BACKUP TESTEN(1)\" 'DIT IS DE SCHIJF EN MAP WAARIN WORDT OPGESLAGEN
Function SelectionSort(TempArray As Variant)
Dim MaxVal As Variant, MaxIndex As Long
Dim i As Integer, j As Integer
    ' Step through the elements in the array starting with the last element in the array.
    For i = UBound(TempArray, 1) To 1 Step -1
        ' Set MaxVal to the element in the array and save the index of this element as MaxIndex.
        MaxVal = TempArray(i)
        MaxIndex = i
        ' Loop through the remaining elements to see if any is larger than MaxVal.
        ' If it is then set this element to be the new MaxVal.
        For j = 1 To i
            If TempArray(j) > MaxVal Then
                MaxVal = TempArray(j)
                MaxIndex = j
            End If
        Next j
        ' If the index of the largest element is not i, then exchange this element with element i.
        If MaxIndex < i Then
            TempArray(MaxIndex) = TempArray(i)
            TempArray(i) = MaxVal
        End If
    Next i
End Function
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ActiveWorkbook.Save
    ' Beginnen met het eerste Excel bestand opzoeken in de standaardmap
    MijnBestand = Dir(sPad & "*.xls")
    ReDim tmp(0)
    i = 0
    'vervolgens alle bestanden in een matrix variabele zetten.
    Do While MijnBestand <> ""
        ReDim Preserve tmp(i)
        tmp(i) = MijnBestand
        i = i + 1
        MijnBestand = Dir
    Loop
    ' Dan de matrix sorteren ...
    Call SelectionSort(tmp)
    ' ... "verwijder alle oude backups behalve de laatste 3
    For i = 0 To UBound(tmp) - 3
        On Error Resume Next
        Kill sPad & tmp(i)
    Next i
    ' En dan natuurlijk een nieuwe backup maken!
    ActiveWorkbook.SaveCopyAs sPad & Format(Now, "yyyy") & Sheets("Blad1").Range("D7").Value & " " & ActiveWorkbook.Name
End Sub
	Bijlagen
			
				Laatst bewerkt: