locked
"Paste with Live Preview" feature of Word 2010 using C# Word Automation RRS feed

  • Question

  • Hi,

    How to implement "Paste with Live Preview" feature of Word 2010 using C# Word Automation?

    I need to do this for Word Add-In functionality. After reading Custom UI XML protocol documentations , I got to know that the paste options IdMso is "PasteGalleryMini" and type is gallery . But I could not find relevant enumeration in Microsoft.Office.Core namespace. 

    Thanks,

    Srinivas Akella

    Tuesday, June 1, 2010 1:41 PM

Answers

  • Hi Srinivas

    Indeed, the CommandBars object model is being phased out and replaced by "Office Fluent UI" - the Ribbon. What's more, in Word 2010 the Paste functionality has been changed, so the old feature will no longer work, as it did in 2007.

    You can repurpose the actual Paste button in Word 2010 by defining Ribbon XML for a document or an Add-in. But if you're automating Word from, for example a Win Forms application you have no longer have access to the user interface or the built-in commands. What kind of solution are you working on, exactly?

    Or, as I mentioned in my previous message, you could try leveraging the Ribbon Accessibility API.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Bessie Zhao Tuesday, June 8, 2010 7:09 AM
    Wednesday, June 2, 2010 3:07 PM

All replies

  • I'm afraid this is not exposed for the developer - it's totally internal to the Word (and other) Office applications.

    You'd have to use standard "Interop" in some form or another to achieve something like this. But there are no "mouse over" types of events that will let you trigger it from the user viewing a "gallery" in the Ribbon. Possibly, you could do something with the Windows API to figure out when the mouse is moving, or with the Ribbon Accessibility. But it's not sure whether the "interop" changing the document content is going to be "fluent" enough to be satisfactory.


    Cindy Meister, VSTO/Word MVP
    Tuesday, June 1, 2010 4:27 PM
  • Thanks for the reply.

    I am trying to use the below logic so that I can handle the paste by myself. But I could not an Enumeration value to pass for the FindControl method in case word 2010 paste options gallery.

    The below code is working fine for word 2007 and word 2003.

    CommandBarButton  pasteOption = (CommandBarButton)m_WordApp.CommandBars[item].FindControl(MsoControlType.msoControlButton, 22, m_Missing, true, false);

     pasteOption.Click += new _CommandBarButtonEvents_ClickEventHandler(btnPasteOption_Click);

    Please suggest.

    Thanks,

    Srinivas Akella

     

    Tuesday, June 1, 2010 4:44 PM
  • Hi Srinivas

    Indeed, the CommandBars object model is being phased out and replaced by "Office Fluent UI" - the Ribbon. What's more, in Word 2010 the Paste functionality has been changed, so the old feature will no longer work, as it did in 2007.

    You can repurpose the actual Paste button in Word 2010 by defining Ribbon XML for a document or an Add-in. But if you're automating Word from, for example a Win Forms application you have no longer have access to the user interface or the built-in commands. What kind of solution are you working on, exactly?

    Or, as I mentioned in my previous message, you could try leveraging the Ribbon Accessibility API.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Bessie Zhao Tuesday, June 8, 2010 7:09 AM
    Wednesday, June 2, 2010 3:07 PM
  • Thanks for the prompt reply.

    I have disabled the Paste with Live Preview feature using below custom UI XML and added a normal paste button to the context menu. i.e. After the user right clicks and chooses paste option , I need to capture the event.

    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">

     

    contextMenus >

     

     contextMenu idMso="ContextMenuText" >

     

    gallery idMso= "PasteGalleryMini" visible="false" />

     

    control idMso="Paste" visible="true"/>

     

    contextMenu>  

     

     

     

     

     

    contextMenus>

     

     

    With above configuration the normal paste functionlity is working fine. However I am not able top capture the Paste click event with the below code.

    CommandBarButton

     

     

    customUI>

    cutOption = null;

     

    CommandBarButton)cbar["Text"].FindControl(MsoControlType.msoControlButton, 22, m_Missing, true, false);

     

    new _CommandBarButtonEvents_ClickEventHandler(btnPasteOption_Click);

    btnPasteOption_Click event handler is not getting called. In this event handler I will write some business logic.

    Basically my requirement is to capture the paste click event incase of word 2010 and execute some business logic inside this event hanlder.

    Indeed I have just seen Ribbon XML in Add-In projects of VS 2010. One thing I felt strange. Even for Word 2010 add-in the custom UI namespace is below.

    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_Load">

    But I feel it should be:

    xmlns="http://schemas.microsoft.com/office/2009/07/customui">

     

    If any other alternativates are present for this requiremnt, please suggest and share code snippets/URLS.

    Thanks,

    Srinivas Akella

     

    cutOption.Click +=

     

    cutOption = (

    </

    </

    </

    <

    <

    <

    <

    Wednesday, June 2, 2010 3:46 PM
  • Hello Srinivas,

    As Cindy said above, CommandBars collection has been replaced by Ribbon in Word 2010. We could use Ribbon to customize Office UI. By using Ribbon Xml to customize context menus, we are not allowed to customize built-in button any more, especially the OnAction. Even if you have written lines for this, it will have no effect. However, we could enable/disable the control on context menus.

    So here I suggest you add a customize button. Then in OnAction callback, use Paste method to paste the content in Clipboard. Code like this: Globals.ThisAddIn.Application.Selection.Paste()

    Best regards,
    Bessie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Thursday, June 3, 2010 3:41 AM