我是从离线资料理找出来的
menxin (2001-11-1 12:37:00)
呵呵,真加这么多呀,好,我给你写一个吧
uses Office2000;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
WordApplication1.Connect;
WordApplication1.Visible:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
var i:Integer;
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);}//你可以把现有的菜单信息放在这个LISTBOX里看一下
Controls[5].Set_Visible(false); //删除菜单,实际是隐藏
Controls[Controls.Count].Set_Caption('我的帮助'); //改菜单项
with Controls.Add(msoControlpopup,EmptyParam,EmptyParam,EmptyParam,true) do begin //增加菜单
Set_Caption('新菜单项');
end;
end;
end;
end;
加事件什么的得改成这样,因为要用到一些接口。
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;