Global definitions are assigned to the workbook collection:
fromopenpyxlimportWorkbookfromopenpyxl.workbook.defined_nameimportDefinedNamefromopenpyxl.utilsimportquote_sheetname,absolute_coordinatewb=Workbook()ws=wb.active# make sure sheetnames and cell references are quoted correctlyref="{quote_sheetname(ws.title)}!{absolute_coordinate('A1:A5')}"defn=DefinedName("global_range",attr_text=ref)wb.defined_names["global_range"]=defn# key and `name` must be the same, the `.add()` method makes this easywb.defined_names.add(new_range)