Results 1 to 3 of 3
  1. #1
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Workbook_BeforeClose and DisplayAlerts (XL97 SR2h)

    How come I still get display alerts when "No" is selected by the user? (Edited so you should be able to drop it into a new workbook at the Workbook event level.)

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Application.DisplayAlerts = False
    Dim intUserAnswer As Integer
    If Not ThisWorkbook.Saved Then
    intUserAnswer = MsgBox("You have made changes to this file." _
    & vbLf & "Do you want to save the file?", vbYesNoCancel + vbExclamation)
    If intUserAnswer = vbYes Then
    Cancel = True 'cancel the close
    'code here
    ElseIf intUserAnswer = vbCancel Then
    Cancel = True 'cancel the close, do nothing
    ElseIf intUserAnswer = vbNo Then
    'code here, close not canceled
    End If
    End If
    Application.DisplayAlerts = True
    End Sub
    -John ... I float in liquid gardens
    UTC -7ąDS

  2. #2
    Star Lounger
    Join Date
    Jan 2001
    Location
    Adelaide, South Australia
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Workbook_BeforeClose and DisplayAlerts (XL97 SR2h)

    John

    You get the display alert because it occurs after this event code has been processed (put a msgbox at the end of your code and see the order that the messages come up in).

    When the user says no, what about setting
    thisworkbook.saved=true
    and then the pesky message should go away.

    Jon

    PS How're things in Utah?

  3. #3
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Workbook_BeforeClose and DisplayAlerts (XL97 SR2h)

    Darn, it's always the simple solution I overlook. <img src=/S/doh.gif border=0 alt=doh width=15 height=15> Thanks!

    Very hot; yesterday was 108
    -John ... I float in liquid gardens
    UTC -7ąDS

Posting Permissions

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