Home |
Search |
Today's Posts |
|
#1
![]() |
|||
|
|||
![]()
I have found code to prevent closure of an application by clicking on the Red X. I placed it on Thisworkbook & it prevents the user from closing by clicking on the Red X.
Here is the code as written at present: Private Sub Workbook_BeforeClose(Cancel As Boolean) If CloseMode = 0 Then Cancel = True MsgBox "The X is disabled, please click on the Exit button.", vbCritical End If End Sub This code is also preventing closure of the workbook/application. I think that once the code runs it is not released, I have not found a solution. I see the code working this way. The user clicks on the X & the above message, pops up & that is the end of the process. The user clicks on Exit & it closes. I do have working code to close the workbook/application. However when the Exit button is clicked at present it goes back to the above code. Something weird is going on . I went back in to the application, Clicked the X, & the message popped up once, & waited for me to respond. Last edited by FrancisM : June 25th 19 at 12:38 PM Reason: Recent change in operation |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have found code to prevent closure of an application by clicking on
the Red X. I placed it on Thisworkbook & it prevents the user from closing by clicking on the Red X. Here is the code as written at present: Private Sub Workbook_BeforeClose(Cancel As Boolean) If CloseMode = 0 Then Cancel = True MsgBox "The X is disabled, please click on the Exit button.", vbCritical End If End Sub This code is also preventing closure of the workbook/application. I think that once the code runs it is not released, I have not found a solution. I see the code working this way. The user clicks on the X & the above message, pops up & that is the end of the process. The user clicks on Exit & it closes. I do have working code to close the workbook/application. However when the Exit button is clicked at present it goes back to the above code. Why not just redirect to Call the process fired by the Exit button -OR- Call Exit button's _Click event so any closing forces your Exit button procedure to run??? -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#3
![]() |
|||
|
|||
![]()
Thank you. I did not think of that. The code works, however, 2 things occur. 1). The msgBox occurs 2x. 2) The workbook closes, but not the application. The same thing happens when the exit button is clicked & call "Exit_Referrals" is present. If "Call Exit_Referrals" is not present, the msgbox appears 1x, and both the workbook & application close without any problem. I have tried to find a solution, but have not been successful.
Here is the current code: Option Explicit Sub Exit_Referrals() Dim MsgBoxResult As Long MsgBoxResult = MsgBox("Would you like to Exit the Referral Workbook?" & vbCr, _ vbYesNo, "Voc. Rehab. - Referral") If MsgBoxResult = vbNo Then Exit Sub ElseIf MsgBoxResult = vbYes Then Sheets("TOC").Select Application.Calculation = xlCalculationAutomatic Application.Quit ThisWorkbook.Close SaveChanges:=True End If End Sub When I moved "Application.Quit" after close, the workbook closed, but not the application. Last edited by FrancisM : June 24th 19 at 01:01 PM Reason: Additional Info |
#4
![]() |
|||
|
|||
![]()
1 problem solved. I changed the code by adding "ThisWorkbook.Saved = True" after "Application.Quit". Now if I click on the exit button, both the workbook & the application close.
Here are the remaining problems: 1) Msg box appearing 2X, 2) when the X is clicked, msg box appearing 2x, & workbook closing not application. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
1 problem solved. I changed the code by adding "ThisWorkbook.Saved =
True" after "Application.Quit". Now if I click on the exit button, both the workbook & the application close. Here are the remaining problems: 1) Msg box appearing 2X, 2) when the X is clicked, msg box appearing 2x, & workbook closing not application. Is the Referrals workbook the only one open? Is your calling procedure in its _BeforeClose event? If so post that code! Where is the Exit_Referrals sub located? Why are you NOT using a global variable to track if the MsgBox result has already been trapped? Also, why do you add vbCr to your message Prompt? -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#6
![]() |
|||
|
|||
![]()
Ok. Here are the answers to your questions.
Is the Referrals workbook the only one open? - Yes Where is the Exit_Referrals sub located? - I t resides in module 1 Why do you add vbCr to your message Prompt? - To start a new line in the message. (Open to suggestions) Here is the before close code: Private Sub Workbook_BeforeClose(Cancel As Boolean) 'Part of code to call a pop up calendar. On Error Resume Next Application.OnKey "+^{C}" Application.CommandBars("Cell").Controls("Insert Date").Delete Call Exit_Referrals End Sub I compared the original post to what I currently have, & noticed a big difference. I am SO SORRY. Here is the current code: Option Explicit Sub Exit_Referrals() Dim MsgBoxResult As String If MsgBox("Would you like to Exit the Referral Workbook?" & vbCr, vbYesNo, "Voc. Rehab. - Referral") = vbNo Then Exit Sub Else Sheets("TOC").Select Application.Calculation = xlCalculationAutomatic ThisWorkbook.Close SaveChanges:=True Application.Quit End If End Sub Regarding "Why are you NOT using a global variable to track if the MsgBox result has already been trapped?" _ I did not know about global variable. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Hyperlink to cell and have it appear at top upper left hand corner | New Users to Excel | |||
Moving Active Cell to Upper Left Hand Corner of Screen | Excel Programming | |||
The 'X' in the upper right hand corner is suddenly dithered? Help | Excel Discussion (Misc queries) | |||
What does a small green triangle in the upper left hand corner of. | Excel Discussion (Misc queries) |