최고의 답변자
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일 수요일 오전 8: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일 수요일 오후 1:35