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

1 answer

  • Votes
  • Date
  • Descending date
  1. Hello,
    closing with save
    ActiveWorkbook.Close True
    1. Hi! I've tried already, but as I was saying, the Excel .exe application keeps running. Moreover, other users still see the document as occupied and have to open it in Read only (which clearly indicates there's a problem).
    2. Without the code and without a crystal ball, it's not easy...
    3. 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
    4. Hello,
      Try instead:
      Private Sub Workbook_Open() Application.WindowState = xlMinimized Application.Visible = False MenuPrincipal.Show ThisWorkbook.Save DoEvents Application.Quit End Sub

      And delete:
      Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) .... 
    5. 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