macro Auto delete file when passed 15 days

  • I have a workbook ,but looking a macro that auto deletes the file when passed 15 days within the workbook.


    Can anyone help

  • Paste this into the ThisWorkbook module :


    Code
    Private Sub Workbook_Open()
     On Error Resume Next
     Dim Edate As Date
     Dim sh As Worksheet
    Edate = Format("30/11/2016", "DD/MM/YYYY") '<----- set the delete date here
         If Date > Edate Then
        DeleteActiveWorkbook
    End If
    End Sub




    Pate this into a Routine Module :



    Code
    Sub DeleteActiveWorkbook()
    Dim xFullName As String
    xFullName = Application.ActiveWorkbook.FullName
    ActiveWorkbook.Saved = True
    Application.ActiveWorkbook.ChangeFileAccess xlReadOnly
    Kill xFullName
    Application.ActiveWorkbook.Close False
    End Sub


    The workbook contents will be deleted but the actual workbook will need to be closed manually by the user.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!