Consulting

Results 1 to 3 of 3

Thread: KillYourSelf.xls warning message problem

  1. #1

    KillYourSelf.xls warning message problem

    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.
    Attached Files Attached Files

  2. #2
    VBAX Regular
    Joined
    May 2011
    Posts
    14
    Location
    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...

    [VBA]
    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

    [/VBA]


    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:
    [VBA]
    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

    [/VBA]

  3. #3
    I copied this code from another forum, sorry for unintentional mistake.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •