PDA

View Full Version : KillYourSelf.xls warning message problem



khaledocom
05-24-2011, 10:54 PM
Hi all,

In the attached, the XL file should kill / delete itself when I close it.
Excel shows a warning message before deletion.
Is there any way to disable this warning message or any message if possible?

Note:
I added the line: application.displayalerts = false but still getting warning Msgs.

Have a gr8 day, thanx in advance.

pjotter
05-25-2011, 12:00 AM
You are kidding right?

In the current Code you are making a MsgBox yourself to warn that you're deleting the workbook... MsgBoxes are not warnings/Alerts, so they cannot be disabled. If you want to get rid of it simply remove the alert.
The Red text isn't needed if you do not want the msgbox to show, remove that and it should work... Also need to remove the If statement since it's dependable on the answer in the msgbox...


Option Explicit

Private Const MSG_TITLE As String = "Deleting Current Workbook ..."
Private Const MSG_TEXT As String = _
"You are about to permanently delete the current workbook located in :"

'pate a ref. to this in before close


Sub Kill_Myself()
Application.DisplayAlerts = False
Dim lUserDecision As Long
Dim sMsg As String

On Error Resume Next

sMsg = "Attention !" & vbNewLine & vbNewLine
sMsg = sMsg & MSG_TEXT & vbNewLine
sMsg = sMsg & "'" & ThisWorkbook.FullName & "'" & vbNewLine
sMsg = sMsg & "from Disk!!" & vbNewLine & vbNewLine
sMsg = sMsg & "Go ahead ?" & vbNewLine & vbNewLine

Beep
lUserDecision = _
MsgBox(sMsg, vbExclamation + vbYesNo, MSG_TITLE)
With ThisWorkbook
If lUserDecision = vbYes Then
.Saved = True
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End If
End With

End Sub




I'd warn you to use it like this though, since you can really get screwed if you do not use it correctly...
Code would become like this:

Option Explicit

'pate a ref. to this in before close

Sub Kill_Myself()
Application.DisplayAlerts = False
Dim lUserDecision As Long

On Error Resume Next

With ThisWorkbook
.Saved = True
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With

End Sub

khaledocom
05-25-2011, 12:21 AM
I copied this code from another forum, sorry for unintentional mistake.