title: Excel Office Add-In API Worksheet Protection Password
body: <p>I have a question relating to Excel's worksheet protection...</p>
  
  <p>The context is that I need to have different worksheets available for different user groups to edit but all groups must at least see all sheets e.g. usergroup1 can edit sheets two and three and parts of sheet one, usergroup2 can edit only sheet one.</p>
  
  <p>I am able to set the FormatProtection (<code>range.format.protection.locked = false;</code>) accordingly and WorksheetProtection (<code>worksheet.protection.protect();</code>) to enable this but I don't appear to have the ability to set a password through the API against the Worksheet Protection? This means for example, that either group can simply click the Unprotect Sheet option in the review ribbon and edit the sheets that I don't want them to.</p>
  
  <p>I've tried going through the below documentation but to no avail unfortunately.</p>
  
  <ul>
  <li><a href="http://dev.office.com/reference/add-ins/excel/worksheetprotection" rel="nofollow">http://dev.office.com/reference/add-ins/excel/worksheetprotection</a></li>
  <li><a href="https://github.com/OfficeDev/office-js-docs/blob/master/reference/excel/worksheetprotection.md" rel="nofollow">https://github.com/OfficeDev/office-js-docs/blob/master/reference/excel/worksheetprotection.md</a></li>
  </ul>
  
  <p>As an example, here is a function that I'd like to complete:</p>
  
  <pre><code>function CopyWorksheet() {
  
          var newAddress;
  
          Excel.run(function (ctx) {
  
              var worksheet = ctx.workbook.worksheets.getActiveWorksheet();
              var range = worksheet.getUsedRange();
              range.load();
  
              // insert new worksheet
              var newWorksheetName = "Copied_Sheet";              
              var newWorksheet = ctx.workbook.worksheets.add(newWorksheetName);
  
              return ctx.sync().then(function () {
  
                  // copy the old values to the new worksheet
                  newAddress = range.address.substring(range.address.indexOf("!") + 1);
                  newWorksheet.getRange(newAddress).values = range.values;
                  newWorksheet.getRange(newAddress).formulas = range.formulas;
                  newWorksheet.getRange(newAddress).text = range.text;
  
                  // protect both worksheets
                  worksheet.protection.protect();
                  newWorksheet.protection.protect();
  
                  // requirement here to set a password so that no one can 
                  // edit the worksheets by selecting 'Unprotect Sheet' in excel
                  // ...
              })
              .then(ctx.sync)})
              .catch(function(error) {
                      console.log("Error: " + error);                     
              });
          }
  </code></pre>
  
  <p>Currently, I'm using Excel 2016 (desktop version). Is this possible to implement or have I missed some functionality that exists which can achieve the same result?</p>
  
  <p>Thanks for your help.</p>