VBA Excel 2007 Security warning when Closing with Task manager

51 Views Asked by At

In Excel 2007 I Create file and macro (vba), I protected workbook using password and to avoid Security warning when closing file through icon red (X) and reopen file and after save my data and indeed, the problem is solved

Steps

  1. to avoid Security warning (code problem solved is down )
  2. Closing file with red icon (X)
  3. Reopen file
  4. Save my work
  5. close and reopen
  6. work fine

But window Security warning arise when Closing file with Task manager and next reopen file, code down not working

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    ThisWorkbook.Unprotect Password:="blabla"
    ThisWorkbook.Save
    ThisWorkbook.Saved = True
End Sub


Private Sub Workbook_Open()
    ThisWorkbook.Protect Password:="blabla"
    ThisWorkbook.Save
    ThisWorkbook.Saved = True
End Sub  
0

There are 0 best solutions below