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

痴心易碎 提交于 2019-12-12 12:34:57

问题


We are inserting content controls programmatically in word document and we don't want to add actions to the undo stack of word. The only way that we found is to access the undo commandbar-combobox 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?

来源:https://stackoverflow.com/questions/10703893/prevent-actions-to-be-added-to-the-word-undo-redo-or-remove-actions-from-the-und

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!