ExcelScript Command to Protect Workbook (And Open in read-only mode)

%3CLINGO-SUB%20id%3D%22lingo-sub-2651888%22%20slang%3D%22en-US%22%3EExcelScript%20Command%20to%20Protect%20Workbook%20(And%20Open%20in%20read-only%20mode)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2651888%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20there%20an%20Excel%20Script%20command%20for%20Excel%20online%20which%20could%20enable%20the%20Protect%20Workbook%20function%20so%20that%20the%20file%20opens%20as%20read%20only%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20do%20this%20manually%2C%20the%20steps%20would%20be%26nbsp%3B%3C%2FP%3E%3CP%3EFile%20%26gt%3B%20Info%20%26gt%3B%20Protect%20Workbook%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22EWLC_0-1629110759239.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F303532iB6769B5E0A7A309A%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22EWLC_0-1629110759239.png%22%20alt%3D%22EWLC_0-1629110759239.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20tried%20running%26nbsp%3B%3CSPAN%3Eworkbook.getProtection().protect()%3B%20however%20this%20does%20not%20seem%20to%20enable%20this%20setting.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EA%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3Eworkbook.getProtection().getProtected()%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2651888%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%20for%20web%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20Scripts%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2659545%22%20slang%3D%22en-US%22%3ERe%3A%20ExcelScript%20Command%20to%20Protect%20Workbook%20(And%20Open%20in%20read-only%20mode)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2659545%22%20slang%3D%22en-US%22%3EThat%20command%20is%20unavailable%20to%20Office%20Script%2C%20you'll%20have%20to%20either%20protect%20the%20workbook%20in%20Desktop%20Excel%20or%20use%20Office%20JS%20to%20change%20that%20setting.%3C%2FLINGO-BODY%3E
New Contributor

Hi,

 

Is there an Excel Script command for Excel online which could enable the Protect Workbook function so that the file opens as read only?

 

To do this manually, the steps would be 

File > Info > Protect Workbook

 

EWLC_0-1629110759239.png

 

I have tried running workbook.getProtection().protect(); however this does not seem to enable this setting.

 

workbook.getProtection().getProtected() 

1 Reply
That command is unavailable to Office Script, you'll have to either protect the workbook in Desktop Excel or use Office JS to change that setting.