pluginguin
New Member
- Joined
- Aug 10, 2016
- Messages
- 21
- Office Version
- 2019
- Platform
- Windows
I have a workbook that, upon opening makes the application invisible and opens it's userform:
There is a button on the form to unhide the parent application again, in order for users to modify the sheets.
When I close the userform using it's X in the top right corner I want it to check two things.
Currently I'm using this code:
But point 2 it is not working.
If the parent application is invisible and I have another workbook open: it closes the other workbook and makes itself visible.
If the parent application is invisible and no other workbooks are open: it closes itself but leaves the application running.
What do I have to change to get it to work?
Thx in advance!
Code:
Private Sub Workbook_Open()
Parent.Application.Visible = False
UserForm1.Show
End Sub
There is a button on the form to unhide the parent application again, in order for users to modify the sheets.
When I close the userform using it's X in the top right corner I want it to check two things.
- If the parent.application is visible it should do nothing. Otherwise check 2.
- If there are more workbooks open it should only close the workbook with the userform and set focus on next workbook, otherwise close excel completely
Currently I'm using this code:
Code:
Private Sub UserForm_Terminate()
If Parent.Application.Visible = False Then
If Application.Workbooks.Count < 2 Then
Parent.Application.Visible = True
ActiveWorkbook.Close SaveChanges:=False
Application.Quit
Else
Parent.Application.Visible = True
ActiveWorkbook.Close SaveChanges:=False
End If
Else
Exit Sub
End If
End Sub
But point 2 it is not working.
If the parent application is invisible and I have another workbook open: it closes the other workbook and makes itself visible.
If the parent application is invisible and no other workbooks are open: it closes itself but leaves the application running.
What do I have to change to get it to work?
Thx in advance!