none
Repurpose Copy/Paste commands for Word 2013 with an Add-In RRS feed

  • Question

  • Hi,

    I'm following this example, http://msdn.microsoft.com/en-us/library/bb462633(v=office.12) ,given for Office 2007, to repurpose the copy/paste commands however I am unable to either run the custom methods on copy/paste or display the custom ribbon button. Here is my current code:

    Imports Microsoft.Office.Core

    Imports Word = Microsoft.Office.Interop.Word Public Class FRibbonAddIn Implements Extensibility.IDTExtensibility2, Microsoft.Office.Core.IRibbonExtensibility Private myRibbon As IRibbonUI Private tempTag As String Private applicationObject As Word.Application

        Private addInInstance As Object Public Function GetCustomUI(RibbonID As String) As String Implements Microsoft.Office.Core.IRibbonExtensibility.GetCustomUI Return "<?xml version=""1.0"" encoding=""UTF-8"" ?>" & _ "<customUI xmlns=""http://schemas.microsoft.com/office/2009/07/customui"" onLoad=""OnLoadRib"">" & _ "<commands>" & _ "<command idMso=""Copy"" onAction=""onCopy""/>" & _ "<command idMso=""Paste"" onAction=""onPaste""/>" & _ " </commands>" & _ "</customUI>" & _ "<ribbon startFromScratch=""false"">" & _ "<tabs>" & _ "<tab id=""tab1"" label=""Repurpose Command Demo"">" & _ "<group id=""group1"" label=""Demo Group"">" & _ "<toggleButton id=""togglebutton1""" & _ "imageMso = ""AcceptInvitation""" & _ "Size = ""large""" & _ "Label = ""Alter Built-ins""" & _ "onAction=""changeRepurpose""/>" & _ "</group>" & _ "</tab>" & _ "</tabs>" & _ "</ribbon>" End Function Public Sub OnLoadRib(ribbon As Office.IRibbonUI) myRibbon = ribbon

    End Sub Public Sub onCopy(control As Office.IRibbonControl, ByRef cancelDefault As Boolean) Me.Application.MessageBox.Show("Copy command has been repurposed") cancelDefault = False End Sub Public Sub onPaste(control As Office.IRibbonControl, ByRef cancelDefault As Boolean) Me.Application.MessageBox.Show("A paste has been performed") cancelDefault = False End Sub Public Sub changeRepurpose(ByVal control As IRibbonControl, ByVal pressed As Boolean) myRibbon.Invalidate() End Sub

    Public Sub OnAddInsUpdate(ByRef custom As Array) Implements Extensibility.IDTExtensibility2.OnAddInsUpdate

        End Sub

        Public Sub OnBeginShutdown(ByRef custom As Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown

        End Sub

        Public Sub OnConnection(Application As Object, ConnectMode As Extensibility.ext_ConnectMode, AddInInst As Object, ByRef custom As Array) Implements Extensibility.IDTExtensibility2.OnConnection
            applicationObject = DirectCast(Application, Word.Application)
            addInInstance = AddInInst
        End Sub

        Public Sub OnDisconnection(RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As Array) Implements Extensibility.IDTExtensibility2.OnDisconnection

        End Sub

        Public Sub OnStartupComplete(ByRef custom As Array) Implements Extensibility.IDTExtensibility2.OnStartupComplete

        End Sub

    End Class

    The only thing I notice I may have gone wrong is that the example suggests to install it by right clicking the solution in the solution explorer which is an option I am not given in Visual Studio 2013. However, I presume this is done automatically on Running the solution though I'm not really sure? I'm also doing this all in the one project, not sure how to get the add-in and Setup projects seperate in 2013, maybe just an 2007 way of doing things?

    Other than that, I'm not really sure. Hope this is still part of the 2013 editions.

    Thanks







    Wednesday, April 2, 2014 2:35 AM

Answers

  • Hi Nathan,

    It is easy to build an Office solution in Visual Studio 2013 and it is a litter difference between with Visual Studio 2005.
    Here is a steps for your reference:
    1. Create a Word add-in project like figure below:
     
    2. Add an xml ribbon like figure below:
     
    3. Custom the ribbon XML

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <commands>
        <command idMso="Copy" onAction="myCopy"/>
        <command idMso="Paste" onAction="myPaste"/>   
      </commands>
      <ribbon>
    
        <tabs>
          <tab idMso="TabAddIns">
            <group id="MyGroup"
                   label="My Group">
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>
    

    4. Add the action for the commands

    Public Sub myCopy(ByVal control As Office.IRibbonControl, ByRef cancelDefault As Boolean)
    
            MsgBox("copy...")
        End Sub
    
        Public Sub myPaste(ByVal control As Office.IRibbonControl, ByRef cancelDefault As Boolean)
            MsgBox("pase...")
    End Sub

    5. Add the CreateRibbonExtensibilityObject sub in ThisAddIn class

    Protected Overrides Function CreateRibbonExtensibilityObject() As  _
        Microsoft.Office.Core.IRibbonExtensibility
            Return New Ribbon1()
    End Function

    In addition, links below may be helpful:
    Walkthrough: Creating a Custom Tab by Using Ribbon XML
    Deploying an Office Solution

    Best regards

    Fei


    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.

    Thursday, April 3, 2014 8:46 AM
    Moderator

All replies

  • Hello Nathan,

    The Ribbon UI was introduced with Office 2007 and did not changed since that time. However, a new namespace is used for new UI features (for example, the Backstage UI). Is this the fase? I'd also recommend checking the RibbonId string before returning the XML markup.

    If you develop a VSTO based add-in you just need to build it for registering. But if you want to deploy your add-in to another PCs you have to create installers. Read more about available options in the Deploying an Office Solution article in MSDN.

    Wednesday, April 2, 2014 8:37 PM
  • Hi Nathan,

    It is easy to build an Office solution in Visual Studio 2013 and it is a litter difference between with Visual Studio 2005.
    Here is a steps for your reference:
    1. Create a Word add-in project like figure below:
     
    2. Add an xml ribbon like figure below:
     
    3. Custom the ribbon XML

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <commands>
        <command idMso="Copy" onAction="myCopy"/>
        <command idMso="Paste" onAction="myPaste"/>   
      </commands>
      <ribbon>
    
        <tabs>
          <tab idMso="TabAddIns">
            <group id="MyGroup"
                   label="My Group">
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>
    

    4. Add the action for the commands

    Public Sub myCopy(ByVal control As Office.IRibbonControl, ByRef cancelDefault As Boolean)
    
            MsgBox("copy...")
        End Sub
    
        Public Sub myPaste(ByVal control As Office.IRibbonControl, ByRef cancelDefault As Boolean)
            MsgBox("pase...")
    End Sub

    5. Add the CreateRibbonExtensibilityObject sub in ThisAddIn class

    Protected Overrides Function CreateRibbonExtensibilityObject() As  _
        Microsoft.Office.Core.IRibbonExtensibility
            Return New Ribbon1()
    End Function

    In addition, links below may be helpful:
    Walkthrough: Creating a Custom Tab by Using Ribbon XML
    Deploying an Office Solution

    Best regards

    Fei


    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.

    Thursday, April 3, 2014 8:46 AM
    Moderator
  • Thanks, works perfectly.

    Just having a bit of trouble with re purposing all the different paste commands now, apparently it worked in 2007 but not 2010 and above:

    http://social.msdn.microsoft.com/Forums/en-US/a553edcb-1ded-4da1-b9c3-85b33f207e19/intercepting-word-2010-paste-commands-is-not-as-easy-as-in-word-2007?forum=worddev

    Fortunately what I primarily want to achieve only needs the copy command, but if there's straightforward way to repurpose commands like "PasteSourceFormatting" and "PasteTextOnly", I'd certainly like to hear it, because I still have a bug related to that to address.

    Thanks


    Tuesday, April 8, 2014 3:00 AM