title: How can I restrict MS-Word to pre-defined styles but still allow inline format changes
body: <p>I am trying to create a MS Word 2013 document-level add-in with Visual Studio Tools for Office (VSTO) that implements a restricted editing environment. Two particular requirements of the add-in are:</p>
  
  <ol>
  <li>The user is restricted to using pre-existing styles. These styles cannot be changed and new styles cannot be created.</li>
  <li>Certain inline formatting changes are allowed, for example, Bold, Italic, Underline, Superscript, Subscript.</li>
  </ol>
  
  <p>I am having trouble creating a solution that satisfies both of these requirements. The approaches I have tried so far have all hit road-blocks:</p>
  
  <h3>A. Use Word's Restrict Editing feature via <code>ThisDocument.Protect(.., enforceStyleLock=true)</code>.</h3>
  
  <ul>
  <li>This satisfies the first requirement, but it also disables all of the inline formatting abilites, in particular all controls on <em>Ribbon->Home_Tab->Font_Group</em>. In addition, the font pop-up with the same controls that usually appears when you hover over some selected text is also disabled.</li>
  <li>I have tried re-enabling the affected commands using a <code>customUI</code> in <em>ribbon.xml</em>, but this appears to be ineffective when the document is protected.</li>
  </ul>
  
  <h3>B. As above, but I've re-implemented controls for the inline formatting operations that I want to allow.</h3>
  
  <ul>
  <li>I can use the same icons from Word and can get Font group on the ribbon that looks pretty close to Word's, but has my re-implemented code behind it.</li>
  <li>There are some subtle issues, such as responding to keyboard shortcuts does not work (e.g. Ctrl-B does not do <strong>Bold</strong> because Word thinks it's disabled), and it's not always possible to reflect the current font characteristics on the re-implemented controls (e.g. if Boldness changes as a result of some operation other than clicking my Bold control, then the control does not know when to update its 'pressed' state). These issues may be solvable with more research but I'm conscious of hitting a never-ending stream of special cases, and of course it does not help with this next item..</li>
  <li>No formatting controls appear when hovering over selected text. I can't find any way to re-implement that Word feature.</li>
  </ul>
  
  <h3>C. Do not use Restrict Editing, but try to emulate its functionality by modifying the UI</h3>
  
  <ul>
  <li>I have a custom <em>ribbon.xml</em> with a <code>&lt;commands&gt;</code> section that disables certain commands which nicely reflects in the built-in controls on the Ribbon</li>
  </ul>
  
  <pre>
      &lt;?xml version="1.0" encoding="UTF-8"?>
      &lt;customUI onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2009/07/customui">
        &lt;commands>
          &lt;command idMso="Font" enabled="false" />
          &lt;command idMso="FontSize" enabled="false" />
          ...
        &lt;/commands>
      &lt;/customUI>
  </pre>
  
  <ul>
  <li>This also works nicely for the pop-up Font control when hovering over selected text.</li>
  <li>There are some things that I cannot figure out how to control:
  
  <ul>
  <li>Right-clicking items in the <em>Styles</em> gallery (<em>Ribbon->Home_Tab->Style_Group</em>) shows a context menu that I cannot control and has unwanted items (such as <em>Modify...</em> and <em>Rename...</em>)</li>
  <li>The <em>Styles</em> pane has a <em>New Style</em> button at the bottom left that I cannot disable (protected mode disables it).</li>
  </ul></li>
  </ul>
  
  <pre>
      &lt;command idMso="StylesPaneNewStyle" enabled="false"/>  (ineffective)
  </pre>
  
  <h2>This leads to some specific questions. Answering any of them will help me move forward:</h2>
  
  <ol>
  <li><p>Are there any other approaches I should consider to implement my restricted editing environment in Word?</p></li>
  <li><p>Regarding approach A, is there a programmatic way to re-enable commands that have been disabled by protecting the document.</p></li>
  <li><p>Regarding approach B, is there a way to re-implement the selected-text font controls pop-up on hover?</p></li>
  <li><p>Regarding approach C, is there a way to influence the <em>Styles</em> context menu and the <em>New Style</em> button in the <em>Styles</em> pane? Alternatively, is there some event I could monitor to determine when style changes have been attempted, and perhaps prevent them?</p></li>
  </ol>