title: Override Word Paste event - VSTO
body: <p>I am working on a Word custom ribbon bar add-in and I need to override the <strong>Word Paste event</strong> and do something more to the pasting range. My current implementation is as follows.</p>
  <p>In the <code>ribbon.xml</code> file,</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;customUI xmlns=&quot;http://schemas.microsoft.com/office/2009/07/customui&quot; onLoad=&quot;Ribbon_Load&quot; &gt;
    &lt;commands&gt;
      &lt;command idMso=&quot;Paste&quot; onAction=&quot;RegenerateIDsAfterPaste&quot;/&gt;
    &lt;/commands&gt;
    &lt;ribbon&gt;
      &lt;tabs&gt;
       ........
      &lt;/tabs&gt;
    &lt;/ribbon&gt;
  &lt;/customUI&gt;
  </code></pre>
  <p>In the <code>ribbon.cs</code> file,</p>
  <pre><code>public void RegenerateIDsAfterPaste(Office.IRibbonControl control, bool cancelDefault)
  {
      Word.Selection selection = Globals.ThisAddIn.Application.Selection;
      Word.Range range = selection.Range;
      range.Paste();
      //more code here
  }
  </code></pre>
  <p>With the current implementation, when I paste the content in the clipboard using <strong>Ctrl+V</strong>, it works well and apply the changes to the pasting range as implemented in the <code>RegenerateIDsAfterPaste</code> method.</p>
  <p>But when I try to paste the content in the clipboard by right clicking on the Word document and clicking the below 1st button, the <code>RegenerateIDsAfterPaste</code> method doesn't even execute. Seems the <code>idMso=Paste</code> doesn't represent this button click.
  <a href="https://i.stack.imgur.com/BWupj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BWupj.png" alt="enter image description here" /></a></p>
  <p>I tried some other idMso vaues related to Paste added in this <a href="https://onlinehelp.ribboncreator.de/EN/_2hm0n9inj.htm" rel="nofollow noreferrer">link</a>. But none of them worked.</p>
  <p>Does anybody have an idea on how should I modify my code so that it works with both <code>Ctrl+V</code> and &quot;Word right click Paste&quot;.</p>
  <p>Thank you in advance.</p>