Python excel protection.set_password error

Good Morning,
I am building a script which removes the read only property from a spreadsheet, opens the spreadsheet, removes the sheet protection, makes a change, readd the sheet protection and reapplies the read only property. However i keep getting an error on the protection.set_password part. The error i am getting is “TypeError: ‘bool’ object is not callable”

The code i am using is below. Does anyone know what is causing the error? as i am not 100% what the error means

import os
import stat
import openpyxl as op
from openpyxl import load_workbook

#Open workbook and check if FRN exists
file_name = r'c:\test.xlsx'
os.chmod(file_name, stat.S_IWRITE)
wb = op.load_workbook(file_name)
ws =
sheet = wb["Sheet1"] = False
ws["A1"] = "TestValue"
pword = 'passw0rd11'
os.chmod(file_name, stat.S_IREAD)


it doesn’t appear that you need this line since you are already getting access to it via tha op prefix.

from openpyxl import load_workbook

The set_password property is a Boolean value. It’s not a method that can be called. I would imagine (but haven’t worked with this) that doing: = False

would restore the password to what it had been.

Thank you so much, it is working fine now.

1 Like