none
Intercepting the basic send email functionality in Word 2010 RRS feed

  • Question

  • Hello

    I am trying to perform some checks before a document is saved, printed or send. I know this used to be possible in Word 2003 by overriding the respective macros in vba, but how can this be done in Word 2010 with the ribbon?

    Friday, March 15, 2013 3:12 PM

Answers

  • Hi Pascal

    Using the Ribbon, you re-purpose commands. Not all commands can be re-purposed: only those that are linked to a button or a toggleButton (not lists, galleries, etc.)

    Your Ribbon XML needs a <commands> element with nested <command> elements for every command you want to repurpose. You specify the msoId for the command and the name of an onAction procedure for the code you want to execute in place of the built-in command.

    You can download a list of ControlIds at http://www.microsoft.com/en-us/download/details.aspx?id=6627

    You can often determine the ControlId by hovering the mouse over the command in the Customize dialog box for the Ribbon in the application UI.


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, March 15, 2013 4:27 PM
    Moderator
  • Hi Pascal

    No, it's not possible to add a Ribbon to an old-format binary file, only to Open XML files.

    Be warned that, as time goes on, re-purposing the commands on the "File" menu is going to become more difficult. In Word 2010 you cannot directly re-purpose the print command. In Word 2013 Save and Save As have been moved to the Backstage, as well, and can no longer be directly re-purposed.

    Instead, you have to work with the EVENTS (DocumentBeforePrint, DocumentBeforeSave) or create your own Backstage interface that replaces Word's built-in one. As far as using events go, you could do this with your old *.dot template and continue to use it for the moment.

    The best way to re-link thousands of *.docx documents would probably be to work over the XML structure, as you surmise. The Open XML SDK makes this a fairly painless task or, if someone is already comfortable with working with Zip packages and XML using a different software, that will work, as well. I believe the attached template assignment is in the SETTINGS.XML file.

    You cannot link a *.dotm to a *.doc.


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, March 20, 2013 11:06 AM
    Moderator

All replies

  • Hi Pascal

    Using the Ribbon, you re-purpose commands. Not all commands can be re-purposed: only those that are linked to a button or a toggleButton (not lists, galleries, etc.)

    Your Ribbon XML needs a <commands> element with nested <command> elements for every command you want to repurpose. You specify the msoId for the command and the name of an onAction procedure for the code you want to execute in place of the built-in command.

    You can download a list of ControlIds at http://www.microsoft.com/en-us/download/details.aspx?id=6627

    You can often determine the ControlId by hovering the mouse over the command in the Customize dialog box for the Ribbon in the application UI.


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, March 15, 2013 4:27 PM
    Moderator
  • Hi Cindy

    Thanks for your reply! It was already useful, but it also brought up some other questions.

    We are currently still using a Word 2003 template in combination with Word 2010 documents. (we only just recently made the switch to Word 2010). So I think there is no way to add Ribbon XML to the (binary) .dot? Please confirm this. (Because as we switched to Word 2010, I launched the question of switching the template too and this was regarded as not needed at the time. All works fine, except for the added functionality of intercepting the Ribbon commands instead of the commandbar commands)

    If we do need to convert the .dot to a .dotm, do you know the best way to relink the many documents (many 10,000 of them) to the .dotm? We already converted most of them from .doc to .docx using a self-made VB.Net program and using the build-in Convert method in every single one of them. I supposed we could tweak this in the XML structure of every docx without the need to open every single document in Word itself? But what about the remaining doc files? Would it cause a problem linking a dotm template to a doc file?

    Thanks in advance

    Wednesday, March 20, 2013 8:56 AM
  • Hi Pascal

    No, it's not possible to add a Ribbon to an old-format binary file, only to Open XML files.

    Be warned that, as time goes on, re-purposing the commands on the "File" menu is going to become more difficult. In Word 2010 you cannot directly re-purpose the print command. In Word 2013 Save and Save As have been moved to the Backstage, as well, and can no longer be directly re-purposed.

    Instead, you have to work with the EVENTS (DocumentBeforePrint, DocumentBeforeSave) or create your own Backstage interface that replaces Word's built-in one. As far as using events go, you could do this with your old *.dot template and continue to use it for the moment.

    The best way to re-link thousands of *.docx documents would probably be to work over the XML structure, as you surmise. The Open XML SDK makes this a fairly painless task or, if someone is already comfortable with working with Zip packages and XML using a different software, that will work, as well. I believe the attached template assignment is in the SETTINGS.XML file.

    You cannot link a *.dotm to a *.doc.


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, March 20, 2013 11:06 AM
    Moderator