最佳解答者
Prevent actions to be added to the word undo redo OR Remove actions from the undo redo CommandBarComboBox

問題
-
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.
2012年5月22日 上午 11:06
解答
所有回覆
-
2012年5月23日 上午 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
2012年5月23日 下午 01:35