av8tordude
02-05-2014, 08:46 AM
I have this code that checks if other workbooks are open. I'm tried many times to reduce the redundant code. Is there a simpler or better way to write this code?
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Workbooks.Count > 1 Then
If MsgBox("You have other workbooks open. Any changes made in the other workbooks will be loss. Do you want to continue?", vbYesNo + vbQuestion) = vbYes Then
'ThisWorkbook.Unprotect Password:="T0nyul!a"
TitleBarOpen
Application.ScreenUpdating = 0
HideAll
'ThisWorkbook.Protect Password:="T0nyul!a"
ThisWorkbook.Save
Application.Visible = False
frmLogo.Show
Application.Visible = True
Application.Quit
Else
Cancel = True
End If
Else
'ThisWorkbook.Unprotect Password:="T0nyul!a"
TitleBarOpen
Application.ScreenUpdating = 0
HideAll
'ThisWorkbook.Protect Password:="T0nyul!a"
ThisWorkbook.Save
Application.Visible = False
frmLogo.Show
Application.Visible = True
Application.Quit
End If
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Workbooks.Count > 1 Then
If MsgBox("You have other workbooks open. Any changes made in the other workbooks will be loss. Do you want to continue?", vbYesNo + vbQuestion) = vbYes Then
'ThisWorkbook.Unprotect Password:="T0nyul!a"
TitleBarOpen
Application.ScreenUpdating = 0
HideAll
'ThisWorkbook.Protect Password:="T0nyul!a"
ThisWorkbook.Save
Application.Visible = False
frmLogo.Show
Application.Visible = True
Application.Quit
Else
Cancel = True
End If
Else
'ThisWorkbook.Unprotect Password:="T0nyul!a"
TitleBarOpen
Application.ScreenUpdating = 0
HideAll
'ThisWorkbook.Protect Password:="T0nyul!a"
ThisWorkbook.Save
Application.Visible = False
frmLogo.Show
Application.Visible = True
Application.Quit
End If
End Sub