Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 219
Default 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

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I create a click on + symbol to open a root and click on -. changeyourbodychallenge.com Excel Discussion (Misc queries) 1 December 28th 09 03:22 PM
How to change syperlink from single click to double click syperlinker Excel Worksheet Functions 0 June 13th 08 05:01 PM
Disabling click and right-click on the Picture I inserted in an Excel document [email protected] Excel Worksheet Functions 1 June 2nd 06 09:13 PM
Click on graph bar to execute a double-click in a pivot table cell [email protected] Charts and Charting in Excel 4 August 3rd 05 01:37 AM
Mouse Over Graph, Capture Information on Click(Double Click) Dean Hinson[_3_] Excel Programming 1 December 6th 04 04:49 AM


All times are GMT +1. The time now is 05:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"