Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 22 of 22

Thread: Stop user from closing workbook until conditions apply

  1. #21
    VBAX Newbie
    Joined
    Dec 2016
    Posts
    3
    Location

    Prevent close except...

    Thanks, I was looking for a workaround from preventing closing if it is me. I have changed gears and am just using a warning now instead of preventing the closing but still interested if someone has an answer.

    You must fill in the data or the workbook will not close. - how do I write an exception in?

  2. #22
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    One way to do this is to ask the question as you close by changing the message box in the original:

    orginal:
    [VBA]If AllowClose Then
    Else
    MsgBox Prompt, vbCritical, "Incomplete Data"
    Cancel = True
    Rng2.Select
    End If[/VBA]

    change this to:

    [VBA]Dim ans As Integer


    If allowclose Then
    Else
    ans = MsgBox("Incomplete data, do you want to close", vbYesNo)
    If (ans = vbNo) Then

    Cancel = True
    End If

    [/VBA]

Posting Permissions

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