MistakesWereMade
Board Regular
- Joined
- May 22, 2019
- Messages
- 103
So I have a form where its workbook is hidden. The user opens a file which generates a separate open workbook. My problem is when I close this other workbook, excel prompts me to save/unsave my userform too...
I've included some code in the ThisWorkbook module that allows me to close a separate workbook once without it prompting me about my userform. But when I open a second workbook and try to close it... It then asks me to close my userform. I want to be able to freely open and close as many separate workbooks as I want to without excel prompting me to close my form.
Any ideas?
I've included the current code from the ThisWorkbook Module...
I've included some code in the ThisWorkbook module that allows me to close a separate workbook once without it prompting me about my userform. But when I open a second workbook and try to close it... It then asks me to close my userform. I want to be able to freely open and close as many separate workbooks as I want to without excel prompting me to close my form.
Any ideas?
I've included the current code from the ThisWorkbook Module...
Code:
Public swb As String
Private Sub Workbook_Open()
Application.ScreenUpdating = False
swb = ThisWorkbook.Name
ThisWorkbook.Application.Visible = False
UserForm1.Show vbModeless
Application.ScreenUpdating = True
End Sub
Private Sub Workbook_BeforeClose(cancel As Boolean)
If swb <> ActiveWorkbook.Name Then
ActiveWorkbook.Close
Application.Visible = False
UserForm1.Show vbModeless
Else
ThisWorkbook.Close
End If
End Sub