Close Workbook on Userform Close
Hello everyone,
I would like to know if it is possible to close Excel when closing a Userform (my userform is actually a kind of main menu)?
I have tried all the commands such as
ActiveWorkbook.Save
.Close
Application.Quit
etc...
But none have really closed the workbook because when we do that, other users will still see the workbook in read-only mode if they try to open it. Moreover, in the task manager, Excel is still running...
Do you have a solution?
Thank you!
Configuration: Android / Chrome 67.0.3396.87
I would like to know if it is possible to close Excel when closing a Userform (my userform is actually a kind of main menu)?
I have tried all the commands such as
ActiveWorkbook.Save
.Close
Application.Quit
etc...
But none have really closed the workbook because when we do that, other users will still see the workbook in read-only mode if they try to open it. Moreover, in the task manager, Excel is still running...
Do you have a solution?
Thank you!
Configuration: Android / Chrome 67.0.3396.87
1 answer
-
Hello,
closing with saveActiveWorkbook.Close True
-
-
-
Thank you for your responses. Here is the code:
Upon opening the WorkBook:
Private Sub Workbook_Open()
'hide excel
Application.WindowState = xlMinimized
Application.Visible = False
'open the main menu userform
MenuPrincipal.Show
End Sub
Upon closing the UserForm serving as the Main Menu:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.Quit
End Sub -
-
Thank you very much for your help, the program works.
I just had a question about how it works because I’m not sure I understand it 100%: When does the backup take place? At what event? I think I don’t understand "DoEvent" despite my research on the web.
Also, can we remove the confirmation message for saving when closing the document? Because anyway, the code you gave me seems to perform the backup automatically.
Anyway, thanks again for your valuable help.
Best regards,
Tagada
-