VBA Excel 2007 Security warning when Closing with Task manager

  • 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

    • to avoid Security warning (code problem solved is down )
    • Closing file with red icon (X)
    • Reopen file
    • Save my work
    • close and reopen
    • work fine

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


    [VBA]
    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
    [/VBA]


    Also posted at:


    https://stackoverflow.com/ques…closing-with-task-manager

  • Hi vbaexceltuto, welcome to OzGrid.


    I see that you've also posted this question on Stack Overflow - please note that as per the forum rules you must provide any links to cross-posts. This is to make sure that members can see if your question has already been answered before working on something for you. I've added them for you on this occasion, but please check the forum rules for next time :)


    With regards to your problem - is the workbook a .xls or .xlsm file? If you force quit a macro-enabled workbook using task manager it can cause Windows/Excel to think that something was corrupt with the code and it will then try to prevent that from happening again by presenting you with a security warning. Is there a reason you're using task manager to quit the file?

  • ok SO thank you for your reply, right I'm taking next time the rules of the forum
    my workbook is a.xlsm and my macro is enabled on the option, macro working fine during closing through red icon (X) for this I'm using the code down.
    Before putting this code, the Security warining was showing during close via red icon (X)
    and using this code the problem during closing with task manager
    for information this problem only in Excel 2007


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

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!