Hi
Here is some code line for your reference.
object oMissing = System.Reflection.Missing.Value;
CommandBar cb;
CommandBarButton cbb;
public void OnStartupComplete(ref System.Array custom)
{
cb =
wdApp.CommandBars.Add("TestToo-lBar",oMissing,oMissing,oMissi-ng);
cbb =
(CommandBarButton)cb.Controls.-Add(MsoControlType.msoControlB-utton,oMissing
,o
Missing,oMissing,oMissing);
cbb.Caption = "TestButton";
cbb.Click+=new
_CommandBarButtonEvents_ClickE-ventHandler(cbb_Click);
}
private Word.Application wdApp=null;
private void cbb_Click(CommandBarButton Ctrl, ref bool CancelDefault)
{
Debug.WriteLine("Button Clicked"+System.DateTime.Now.T-oString());
try
{
VBE.VBComponent vbc
=wdApp.ActiveDocument.VBProjec-t.VBComponents.Add(VBE.vbext_C-omponentType.v
be
xt_ct_StdModule);
vbc.Name = "Hello";
vbc.CodeModule.InsertLines(1,"-Sub EditUndo()\nMsgBox
\"Undo Hooked\"\nEnd
Sub");
}
catch(Exception ex)
{
Debug.WriteLine(ex.ToString())-;
}
Debug.WriteLine("Button Clicked"+System.DateTime.Now.T-oString());
}
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.