none
Remove Undo Item in PowerPoint RRS feed

  • Question

  • Is it possible to remove Undo Items in PowerPoint?

    I can get a list of Undo actions list with the following code:

    Microsoft.Office.Core.CommandBarComboBox cmd = null;
    
    try
    {
        cmd = (Microsoft.Office.Core.CommandBarComboBox)
                     PowerPointApp.CommandBars.FindControl(Id: 128);
    }
    catch
    {
    
    }
    
    

    and then I can detect what action the user has performed like

    if (cmd == null) return;
    
    if (cmd.Caption == "&Undo Cut")
    {
        MessageBox.Show("Cut Event");
    }
    else if (cmd.Caption == "&Undo Clear")
    {
        MessageBox.Show("Delete Event");
    }
    //... insert, paste, 
    
    

    And combine the code from https://code.msdn.microsoft.com/CSExcelNewEventForShapes-0e26b1f2, I got absolutely all info about each shape event.

    Now, I try to control the undo stack (e.g., remove an undo action from stack, or clear all undo stack) by the following code:

    cmd.reset(); //- hope, it can clear all undo stack
    cmd.removeItem(2); //- hope it can remove the second undo action from the undo list
    
    

    2 questions are given:

    1) These 2 above lines code do not help, it crashes every time . How can I fix it? Or I cannot control the undo list???

    2) Another question is with the above code, I still cannot detect when the user perform a copy action. Like, when the user selects a shape and clicks on "Copy button" or "Cltr+C", I cannot detect this action. How can I detect it?

    Monday, October 20, 2014 10:14 AM

Answers

  • Hello,

    1) These 2 above lines code do not help, it crashes every time . How can I fix it? Or I cannot control the undo list???

    The fact is that Office doesn't use command bars any longer. They are deprecated. You need to use the Fluent UI (aka Ribbon UI) instead.

    2) Another question is with the above code, I still cannot detect when the user perform a copy action. Like, when the user selects a shape and clicks on "Copy button" or "Cltr+C", I cannot detect this action. How can I detect it?

    As I said earlier, you need to use the Fluent UI. You can intercept the button click, see Temporarily Repurpose Commands on the Office Fluent Ribbon for more information.

    But VSTO (nor Office) doesn't provide anything for handling keyboard shortcuts. You need to use Windows API functions to set up a keyboard hook. See Using shortcut keys to call a function in an Office Add-in for more information.

    • Marked as answer by chipbk11 Tuesday, October 21, 2014 7:34 AM
    Monday, October 20, 2014 2:51 PM

All replies

  • Maybe this answered thread will help you.

    Remove Undo Stack Entry


    Kind Regards, Rich ... http://greatcirclelearning.com

    Monday, October 20, 2014 10:28 AM
  • Maybe this answered thread will help you.

    Remove Undo Stack Entry


    Kind Regards, Rich ... http://greatcirclelearning.com

     @Rich Michaels:  This is totally different Undo Stack. It's not related to built-in undo stack in PowerPoint. Anyway, thanks for your suggestion.

    Any other idea?

    Monday, October 20, 2014 10:33 AM
  • Hello,

    1) These 2 above lines code do not help, it crashes every time . How can I fix it? Or I cannot control the undo list???

    The fact is that Office doesn't use command bars any longer. They are deprecated. You need to use the Fluent UI (aka Ribbon UI) instead.

    2) Another question is with the above code, I still cannot detect when the user perform a copy action. Like, when the user selects a shape and clicks on "Copy button" or "Cltr+C", I cannot detect this action. How can I detect it?

    As I said earlier, you need to use the Fluent UI. You can intercept the button click, see Temporarily Repurpose Commands on the Office Fluent Ribbon for more information.

    But VSTO (nor Office) doesn't provide anything for handling keyboard shortcuts. You need to use Windows API functions to set up a keyboard hook. See Using shortcut keys to call a function in an Office Add-in for more information.

    • Marked as answer by chipbk11 Tuesday, October 21, 2014 7:34 AM
    Monday, October 20, 2014 2:51 PM
  • @Eugene: Your answer is great. It leads me to another approach. However, I am still wondering whether we can catch the event (e.g., Copy - Ctrl C, Paste - Ctrl V) using 2 ways you mention above, and is it possible to use our custom event handle and cancel the PowerPoint built-in handle ?

    For example,

    the user presses Cltr Z (or click on button Cut from Menu), is it possible to use our custom cut function and do not use the PowerPoint built-in cut function? 

    It seems that "Temporarily Repurpose Commands on the Office Fluent Ribbon" can solve this issue, but the "Using Shortcut keys to call a function in an Office Add-in" cannot solve it
    Monday, October 20, 2014 3:57 PM
  • >> I am still wondering whether we can catch the event (e.g., Copy - Ctrl C, Paste - Ctrl V) using 2 ways you mention above, and is it possible to use our custom event handle and cancel the PowerPoint built-in handle ?

    Try using the keyboard hook. The Office extensibility model doesn't provide anything for this. You can repurpose ribbon controls, but not keyboard shortcuts.

    Monday, October 20, 2014 5:34 PM