在VSTO中我们可以通过以下代码来获取Undo按钮的列表:
private static Office.CommandBars getCommandBars()
{
return (Office.CommandBars)Globals.ThisWorkbook.Application.GetType().InvokeMember("CommandBars"
, System.Reflection.BindingFlags.GetProperty,
null,
Globals.ThisWorkbook.Application,
null,
System.Globalization.CultureInfo.InvariantCulture);
}
private static string getLastUndo()
{
string result = string.Empty;
Office.CommandBars oCommandBars = getCommandBars();
Office.CommandBar oCommandBar = oCommandBars["Standard"];
Office.CommandBarControl oCommandBarControl = (Office.CommandBarControl)oCommandBar.Controls[14];
MessageBox.Show(oCommandBarControl.Caption);
MessageBox.Show(oCommandBarControl.accChildCount.ToString());
try
{
if (oCommandBarControl is Office.CommandBarComboBox)
{
Office.CommandBarComboBox ocbcb = (Office.CommandBarComboBox)oCommandBarControl;
for (int i = 1; i < oCommandBarControl.accChildCount; i++)
{
MessageBox.Show(ocbcb.get_List(i));
}
}
else
{
MessageBox.Show("No");
}
}catch(Exception ex){
MessageBox.Show(ex.Message);
}
return result;
}
欢迎访问《 许阳的红泥屋 》