简体   繁体   中英

Excel VBA password protection appears broken

I have never seen anything like this before. I use this code to set a password

Impact_Chart.Unprotect Password:="********" 

With Impact_Chart
    .Range("A19:N19").Locked = False

    .Shapes("Button 36").Locked = False
    .Shapes("Button 19").Locked = False
    .Shapes("Button 37").Locked = False
    .Shapes("Button 38").Locked = False
    .Protect Password:="********", Userinterfaceonly:=True
    .Protect AllowInsertingRows = True, AllowFormattingCells:=True, AllowSorting:=True
End With

The problem I encounter is that after setting the password then saving the workbook is that when I came back later the password is no longer valid. I have to use a password breaker to unprotect the sheet.

Does anyone have any information? I've been Googling all morning and can't seem to find an answer.

I tried your code and it started acting strangely - I think it's because of the last two rows which are broken on to two separate lines. If you combine them then things should work correctly since I believe that once you protect a worksheet you cannot then modify the parameters of the protection.

Try the following code instead:

Impact_Chart.Unprotect Password:="********" 

With Impact_Chart
    .Range("A19:N19").Locked = False

    .Shapes("Button 36").Locked = False
    .Shapes("Button 19").Locked = False
    .Shapes("Button 37").Locked = False
    .Shapes("Button 38").Locked = False
    .Protect Password:="********", Userinterfaceonly:=True, AllowInsertingRows:=True, AllowFormattingCells:=True, AllowSorting:=True
End With

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM