+ Reply to Thread
Results 1 to 5 of 5

Why must I click twice?

  1. #1
    Registered User
    Join Date
    11-09-2005
    Posts
    10

    Smile Why must I click twice?

    I've created a macro to remind users to complete a specific worksheet within a workbook before closing. A pop-up asks "Have you completed the T2020 (worksheet)?" If the user clicks "No", then close will be cancelled and the user will be able to update the worksheet as required. If the user clicks "Yes", then the workbook will close. Here's my problem:
    For some reason, the user must click "Yes" twice before the workbook will close. Or, if the user clicks "Yes" then "No" it will still close. Either way, two mouse clicks are required to close the workbook. Why? Any thoughts?
    Thanks in advance for your help!

    Here's the macro:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Sheets("T2020").Select

    x = MsgBox("Have you updated the T2020?", vbYesNo, "T2020 Reminder")

    If x = vbYes Then
    ThisWorkbook.Close
    End
    End If
    If x = vbNo Then
    Cancel = True
    End
    End If

    End Sub

  2. #2
    Tom Ogilvy
    Guest

    Re: Why must I click twice?

    The workbook is already set to close - you don't need to close it and fire
    the beforeclose event again.

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Sheets("T2020").Select

    x = MsgBox("Have you updated the T2020?", vbYesNo, "T2020 Reminder")

    If x = vbNo Then
    Cancel = True
    End If

    End Sub

    --
    Regards,
    Tom Ogilvy



    "zenahs" <zenahs.1y8qtp_1131558912.375@excelforum-nospam.com> wrote in
    message news:zenahs.1y8qtp_1131558912.375@excelforum-nospam.com...
    >
    > I've created a macro to remind users to complete a specific worksheet
    > within a workbook before closing. A pop-up asks "Have you completed
    > the T2020 (worksheet)?" If the user clicks "No", then close will be
    > cancelled and the user will be able to update the worksheet as
    > required. If the user clicks "Yes", then the workbook will close.
    > Here's my problem:
    > For some reason, the user must click "Yes" twice before the workbook
    > will close. Or, if the user clicks "Yes" then "No" it will still
    > close. Either way, two mouse clicks are required to close the
    > workbook. Why? Any thoughts?
    > Thanks in advance for your help!
    >
    > Here's the macro:
    >
    > Private Sub Workbook_BeforeClose(Cancel As Boolean)
    > Sheets("T2020").Select
    >
    > x = MsgBox("Have you updated the T2020?", vbYesNo, "T2020 Reminder")
    >
    > If x = vbYes Then
    > ThisWorkbook.Close
    > End
    > End If
    > If x = vbNo Then
    > Cancel = True
    > End
    > End If
    >
    > End Sub
    >
    >
    > --
    > zenahs
    > ------------------------------------------------------------------------
    > zenahs's Profile:

    http://www.excelforum.com/member.php...o&userid=28681
    > View this thread: http://www.excelforum.com/showthread...hreadid=483599
    >




  3. #3
    Bob Phillips
    Guest

    Re: Why must I click twice?

    You don't need the Close within the script

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Sheets("T2020").Select

    x = MsgBox("Have you updated the T2020?", vbYesNo, "T2020 Reminder")

    If x = vbNo Then
    Cancel = True
    End
    End If

    End Sub


    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "zenahs" <zenahs.1y8qtp_1131558912.375@excelforum-nospam.com> wrote in
    message news:zenahs.1y8qtp_1131558912.375@excelforum-nospam.com...
    >
    > I've created a macro to remind users to complete a specific worksheet
    > within a workbook before closing. A pop-up asks "Have you completed
    > the T2020 (worksheet)?" If the user clicks "No", then close will be
    > cancelled and the user will be able to update the worksheet as
    > required. If the user clicks "Yes", then the workbook will close.
    > Here's my problem:
    > For some reason, the user must click "Yes" twice before the workbook
    > will close. Or, if the user clicks "Yes" then "No" it will still
    > close. Either way, two mouse clicks are required to close the
    > workbook. Why? Any thoughts?
    > Thanks in advance for your help!
    >
    > Here's the macro:
    >
    > Private Sub Workbook_BeforeClose(Cancel As Boolean)
    > Sheets("T2020").Select
    >
    > x = MsgBox("Have you updated the T2020?", vbYesNo, "T2020 Reminder")
    >
    > If x = vbYes Then
    > ThisWorkbook.Close
    > End
    > End If
    > If x = vbNo Then
    > Cancel = True
    > End
    > End If
    >
    > End Sub
    >
    >
    > --
    > zenahs
    > ------------------------------------------------------------------------
    > zenahs's Profile:

    http://www.excelforum.com/member.php...o&userid=28681
    > View this thread: http://www.excelforum.com/showthread...hreadid=483599
    >




  4. #4
    Registered User
    Join Date
    11-09-2005
    Posts
    10

    Thanks!!

    Thank you for the quick response. It works perfectly now!

  5. #5
    Gary L Brown
    Guest

    RE: Why must I click twice?

    The first question your macro asks is 'Have you completed the T2020
    (worksheet)?'.
    The second question is 'Do you want to save the changes you made to ....."
    with 'Yes/No/Cancel' options.

    If you want the workbook to always save before closing (without asking),
    use...

    ThisWorkbook.Close SaveChanges:=True

    If you NEVER want the workbook to save before closing (without asking), use...

    ThisWorkbook.Close SaveChanges:=False

    Instead of...
    ThisWorkbook.Close

    HTH,
    --
    Gary Brown
    gary_brown@ge_NOSPAM.com
    If this post was helpful, please click the ''''Yes'''' button next to
    ''''Was this Post Helpfull to you?".


    "zenahs" wrote:

    >
    > I've created a macro to remind users to complete a specific worksheet
    > within a workbook before closing. A pop-up asks "Have you completed
    > the T2020 (worksheet)?" If the user clicks "No", then close will be
    > cancelled and the user will be able to update the worksheet as
    > required. If the user clicks "Yes", then the workbook will close.
    > Here's my problem:
    > For some reason, the user must click "Yes" twice before the workbook
    > will close. Or, if the user clicks "Yes" then "No" it will still
    > close. Either way, two mouse clicks are required to close the
    > workbook. Why? Any thoughts?
    > Thanks in advance for your help!
    >
    > Here's the macro:
    >
    > Private Sub Workbook_BeforeClose(Cancel As Boolean)
    > Sheets("T2020").Select
    >
    > x = MsgBox("Have you updated the T2020?", vbYesNo, "T2020 Reminder")
    >
    > If x = vbYes Then
    > ThisWorkbook.Close
    > End
    > End If
    > If x = vbNo Then
    > Cancel = True
    > End
    > End If
    >
    > End Sub
    >
    >
    > --
    > zenahs
    > ------------------------------------------------------------------------
    > zenahs's Profile: http://www.excelforum.com/member.php...o&userid=28681
    > View this thread: http://www.excelforum.com/showthread...hreadid=483599
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1