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 -- zenahs ------------------------------------------------------------------------ zenahs's Profile: http://www.excelforum.com/member.php...o&userid=28681 View this thread: http://www.excelforum.com/showthread...hreadid=483599 |
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" wrote in message ... 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 |
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" wrote in message ... 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 |
Why must I click twice?
Thank you for the quick response. It works perfectly now! -- zenahs ------------------------------------------------------------------------ zenahs's Profile: http://www.excelforum.com/member.php...o&userid=28681 View this thread: http://www.excelforum.com/showthread...hreadid=483599 |
All times are GMT +1. The time now is 08:51 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com