locked
Prevent actions to be added to the word undo redo OR Remove actions from the undo redo CommandBarComboBox RRS feed

  • Întrebare

  • We are inserting content controls programmatically and we dont want to add actions to the undo stack of word. The only way that we found is to acess the undo command bar combox and to remove the items related to inserting content control action, we are using the code below :

    var commandBars = _wordDocument.CommandBars.Cast<CommandBar>();
                var standardCommandBar = commandBars.First(bar => bar.Name.Equals("Standard"));
                CommandBarComboBox undoControl = standardCommandBar.Controls.Cast<CommandBarControl>().First(control => control.Id == 128) as CommandBarComboBox;
    
    undoControl.RemoveItem(1);

    The last line (undoControl.RemoveItem(1)) throws a ComException (HRESULT E_FAIL).

    Is there any way to remove actions from the undo redo combo box?

    Regards.

    marți, 22 mai 2012 11:06

Răspunsuri

  • Hi Tunesian

    Ah, sorry, my brain wasn't quite with it: The UndoClear method will empty the list. That's the best you can do.


    Cindy Meister, VSTO/Word MVP

    miercuri, 23 mai 2012 14:55

Toate mesajele

  • Hi Tunisian_BB,

    Would you please clarify your Word version?

    Best Regards,

    T.X.

    marți, 22 mai 2012 22:45
  • Hi Tx_OfficeDev,

    We  are using word 2010

    Regards

    miercuri, 23 mai 2012 08:29
  • Hi Tunesian

    In Word 2010, and only (so far) in that version it's possible to to group actions from the Undo list into a single command. See the Word.Application.UndoRecord property.

    Then use the Document.Undo method on the document being processed to remove that from the Undo listing.

    In Word 2010 the commands in the Ribbon cannot be cast to CommandBar controls - those don't "exist" any more. And even when they could, it wasn't possible to manipulate the built-in controls the way you're trying to do.


    Cindy Meister, VSTO/Word MVP

    miercuri, 23 mai 2012 13:35
  • Hi Cindy,

    I can't call Undo method, this will undo the action but my need is to remove the action from the stack without undoing the action, I hope I was clear,

    Regards. 

    miercuri, 23 mai 2012 13:42
  • Hi Tunesian

    Ah, sorry, my brain wasn't quite with it: The UndoClear method will empty the list. That's the best you can do.


    Cindy Meister, VSTO/Word MVP

    miercuri, 23 mai 2012 14:55
  • Thanx Cindy for your help.
    miercuri, 23 mai 2012 14:58
  • Has it been solved since it's 2020 now?
    joi, 9 aprilie 2020 07:23