none
Range.Paste with Content controls RRS feed

  • Question

  • Hello Word,

    I want to unable paste into a word document when Clipboard contains Content Controls.

    So I added a ribbon.xml with :

    <commands>
        <command idMso="Paste" onAction="MyPaste" />
      </commands>

    And I added the method :

     public void myPaste(Office.IRibbonControl control, ref bool CancelDefault)
            {
                IDataObject objDataObject = Clipboard.GetDataObject();      
    
                System.Windows.Forms.MessageBox.Show("End of Paste");
            }

    So this code is OK.

    And now I want to know if Clipboard.GetDataObject() contains content controls.

    Please help me. 

    Tuesday, October 20, 2015 9:26 AM

Answers

  • Hi CubeAndLeafInMsdn,

    >> now I want to know if Clipboard.GetDataObject() contains content controls.
    I think we could not achieve this with “Clipboard.GetDataObject()”. The object did not supply such property.

    For a workaround, I suggest you check whether the section contains content controls when you copy, and then check the value when you paste.

    Here is a simple code:

            private int i = 0;
            private Range r;
            public void MyCopy(Office.IRibbonControl control, ref bool CancelDefault)
            {         
                r = Globals.ThisAddIn.Application.ActiveDocument.ActiveWindow.Selection.Range;
                r.Copy();
                i = r.ContentControls.Count;            
            }
            public void myPaste(Office.IRibbonControl control, ref bool CancelDefault)
            {
                r = Globals.ThisAddIn.Application.ActiveDocument.ActiveWindow.Selection.Range;
                if (i > 0)
                {
                    System.Windows.Forms.MessageBox.Show("End of Paste");
                }
                else {
                    r.Paste(); 
                }
    
            }

    Best Regards,

    Edward

              

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, October 21, 2015 3:34 AM