Test
Code:Sub FileKill() If ActiveWorkbook Is Nothing Then MsgBox "There is no active workbook!", vbOKOnly + vbInformation, "Delete File" Exit Sub End If If vbYes = MsgBox("Do you want to delete this file?", vbYesNo + vbQuestion, "Delete " & ActiveWorkbook.Name) Then If ActiveWorkbook.MultiUserEditing Then MsgBox "The activeworkbook is a shared file, and hence it is recommended not to delete the same." & vbLf & vbLf & _ "Remove workbook sharing, and try again.", vbOKOnly + vbInformation, "Shared File" Else If InStr(1, ActiveWorkbook.FullName, Application.PathSeparator) > 0 Then If ActiveWorkbook.ReadOnly = False Then If Not ActiveWorkbook.Saved Then If vbCancel = MsgBox("This workbook hasn't been saved. In case you intended for it to be saved, this is to warn you that it isn't." & _ vbLf & vbLf & "In any case you wanted to delete the file, right? So this message is probably irrelevant anyway." & _ vbLf & vbLf & "So deleting file....") Then Exit Sub Else ActiveWorkbook.Saved = True End If End If ActiveWorkbook.ChangeFileAccess xlReadOnly Kill ActiveWorkbook.FullName ActiveWorkbook.Close 0 End If Else MsgBox "This file doesn't seem to have been saved ever!" & vbLf & vbLf & "Why don't you just close it?!", vbOKOnly + vbExclamation, "New Workbook - " & ActiveWorkbook.FullName End If End If End If End Sub


Reply With Quote
Bookmarks