Unable to unprotect worksheet in Xlwings

45 views Asked by At

I am running xlwings on Windows. When my code hits the unprotection of the sheet, the code just sits there. No exceptions, no popups appeared in Excel, just hanging. I can manually remove protection, the password is fine.

 with xw.App() as app:   
        
        wb = app.books.open(local_filename)
        alerts = wb.api.Application.DisplayAlerts  
        wb.api.Application.DisplayAlerts = False
        
        
        ws_data = wb.sheets["Data Input (Do not rename)"]
            
        if wb.api.ProtectStructure:
            wb.api.Unprotect(Password="xxx")
            
        if ws_data.api.ProtectContents:
            ws_data.api.unprotect(Password="xxx")  # hangs here forever
    
0

There are 0 answers