Thank you for the replay Mallycat!
At first I had some trouble inserting all the right code in the right place after your suggestion.
So...
this goes to the "Sheet1(Sheet1)" code
Private Sub Worksheet_Activate()
If MySheetHidden = True Then UserForm1.Show
End Sub
this goes to the "ThisWorkbook" code
Private Sub Workbook_Open()
If Sheets("Sheet1").Visible = False Then MySheetHidden = True
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Sheets("Sheet1").Visible = True Then
MySheetHidden = False
Else: MySheetHidden = True
End If
Worksheets("Sheet2").Cells(1, 1) = MySheetHidden
End Sub
and
MySheetHidden = True OR MySheetHidden = False
in the form, wherever changes are being made to the state of Sheet1 (hidden or unhidden).
I've spotted one small problem with this code: you were supposed to close the file to get the Boolean variable MySheetHidden to update.
In fact, if you were hiding Sheet1 and not trying to close the file, when you would unhide it, the form wouldn't pop-up. So I had to link the variable update to one more event and because of (or thanks to) the fact that when you hide a Sheet, Excel automatically selects the next Sheet, all I had to do was to add 3 lines to the "Sheet2(Sheet2)" code:
Private Sub Worksheet_Activate()
If Sheets("sheet1").Visible = False Then MySheetHidden = True
End Sub
So that's the smart macro that I was looking for and right now I personally see no flaw in it.
Bookmarks