procedure TForm1.Button2Click(Sender: TObject);
var i:Integer;
b:CommandBarPopup;
c:CommandBarButton;
begin
if WordApplication1.CommandBars.ActiveMenuBar.Enabled then begin
with WordApplication1.CommandBars.ActiveMenuBar do begin
ListBox1.Clear;
for i:=1 to Controls.Count do
ListBox1.Items.Add(Controls.Caption);
Controls[5].Set_Visible(false);
Controls[Controls.Count].Set_Caption('我的帮助');
b:=Controls.Add(msoControlpopup,EmptyParam,EmptyParam,EmptyParam,true) as commandbarpopup; //创建menuitem
with b do begin
Set_Caption('a项');
c:=Controls.Add(msoControlButton,EmptyParam,EmptyParam,EmptyParam,true) as CommandBarButton;
c.Set_Caption('我的第一个菜单项');
c.Set_OnAction('MBClick2'); //将一个宏赋值给这个ITEM
end;
end;
end;
end;