Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am trying to force closure of an Excel 2003 workbook via VBA behind a user
form rather than with the normal File | Close or X and have tried several different approaches; none of which solves the problem. When the user form is hidden, the File | Save and X close options are available and if selected cause a fatal crash. I want to retain the ability to save and close normally for program maintenance, but want to present a normal user with a message and process to exit the program via the user form. I have tried code in Workbook_BeforeClose, but it seems that the routine gets called twice. It works as expected the second time through. The code I'm using is: Private Sub Workbook_BeforeClose(Cancel As Boolean) 'Check to see if frmEntry is loaded If isFormLoaded(frmEntry) Then MsgBox "You must close the application via the Exit button on the Entry form." 'Restore form frmEntry.Show End If End Sub It calls the function below: Function isFormLoaded(frmName As Object) As Boolean Dim intI As Integer 'initialize the return value to false isFormLoaded = False 'loop through all open forms For intI = 0 To UserForms.Count - 1 'test to see if the current form has the 'same name as the frmName If UserForms(intI) Is frmName Then 'return true isFormLoaded = True 'exit the loop Exit For End If Next End Function Any help you can provide with this code or any other options will be sincerely appreciated. Thanks... |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
"Excel encountered an error and had to remove some formatting toavoid corrupting the workbook. Please re-check your formatting carefully." | Excel Discussion (Misc queries) | |||
Error: "Excel encountered an error and had to remove some formatti | Excel Discussion (Misc queries) | |||
can I bypass "Windows has encountered a problem" | Excel Discussion (Misc queries) | |||
XL "encountered a problem & needs to close" | Excel Programming | |||
"Microsoft Excel has encountered a problem..." | Excel Programming |