通过OLE如何控制word菜单(100分)

  • 主题发起人 主题发起人 liyp
  • 开始时间 开始时间
L

liyp

Unregistered / Unconfirmed
GUEST, unregistred user!
在DELIPH中,如何控制或定制WORD菜单。<br>请各位赐教。
 
查 office 目录下的 msword.hlp, 有关于word对象及控制的方法(VB语法)
 
请看我写的如下代码:<br>// 创建WordApplication对象<br>&nbsp; &nbsp; &nbsp;WordApp:=CreateComObject(CLASS_Application) as _Application;<br>procedure VisibleMemu(X,y:Integer;FWordApp: _Application;Visibled:Boolean);<br>var Bak:CommandBar;<br>&nbsp; &nbsp; Bak1:CommandBarPopup;<br>&nbsp; &nbsp; i:Integer;<br>begin<br>&nbsp;for i:=1 to FWordApp.CommandBars.Count do<br>&nbsp; if UpperCase(FWordApp.CommandBars.Item.Name)='MENU BAR' then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; Bak:=FWordApp.CommandBars.Item;<br>&nbsp; &nbsp; Break;<br>&nbsp; &nbsp;end;<br>&nbsp;Bak1:=Bak.Controls.Item[x] As CommandBarPopup;<br>&nbsp;if y&lt;=0 then<br>&nbsp; &nbsp;Bak1.Visible:=False<br>&nbsp; else<br>&nbsp; &nbsp;Bak1.Controls.Item[y].Visible:=Visibled;<br>end;<br><br>Function ModifyMemuCaption(X,y:Integer;FWordApp: _Application;NewCaption:String):String;<br>var Bak:CommandBar;<br>&nbsp; &nbsp; Bak1:CommandBarPopup;<br>&nbsp; &nbsp; i:Integer;<br>begin<br>&nbsp;for i:=1 to FWordApp.CommandBars.Count do<br>&nbsp; if UpperCase(FWordApp.CommandBars.Item.Name)='MENU BAR' then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; Bak:=FWordApp.CommandBars.Item;<br>&nbsp; &nbsp; Break;<br>&nbsp; &nbsp;end;<br>&nbsp;Bak1:=Bak.Controls.Item[x] As CommandBarPopup;<br>&nbsp;result:=Bak1.Controls.Item[y].Caption;<br>&nbsp;Bak1.Controls.Item[y].Caption:=NewCaption;<br>end;<br><br>procedure AddMemuItems(X,y:Integer;FWordApp: _Application;NewCaption:String);<br>var Bak:CommandBar;<br>&nbsp; &nbsp; Bak1:CommandBarPopup;<br>&nbsp; &nbsp; i:Integer;<br>&nbsp; &nbsp; Type1, Id1, Parameter1, Before1, Temporary1:Variant;<br>begin<br>&nbsp;for i:=1 to FWordApp.CommandBars.Count do<br>&nbsp; if UpperCase(FWordApp.CommandBars.Item.Name)='MENU BAR' then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; Bak:=FWordApp.CommandBars.Item;<br>&nbsp; &nbsp; Break;<br>&nbsp; &nbsp;end;<br>&nbsp;Bak1:=Bak.Controls.Item[Bak.Controls.Count] As CommandBarPopup;<br>&nbsp;if x&lt;=0 then<br>&nbsp; begin<br>&nbsp; &nbsp;Type1:=msoControlDropdown;<br>&nbsp; &nbsp;Id1:=Bak1.Id+1;<br>&nbsp; &nbsp;Parameter1:=Unassigned;<br>&nbsp; &nbsp;Before1:=y;<br>&nbsp; &nbsp;Temporary1:=True;<br>&nbsp; &nbsp;with Bak.Controls.Add(Type1,Id1,Parameter1,Before1,Temporary1) do<br><br>&nbsp; &nbsp; &nbsp;Caption:=NewCaption;<br><br>&nbsp; end<br>&nbsp; else<br>&nbsp; begin<br>&nbsp; &nbsp;Parameter1:='';<br>&nbsp; &nbsp;Temporary1:=True;<br>&nbsp; &nbsp;Id1:=Bak.Controls.Item[Bak.Controls.Count].ID+1;<br>&nbsp; &nbsp;Bak1:=Bak.Controls.Item[x] As CommandBarPopup;<br>&nbsp; &nbsp;with Bak1.Controls.Add(msoControlPopup,Id1,Parameter1,y,Temporary1) do<br>&nbsp; &nbsp; &nbsp;Caption:=NewCaption;<br>&nbsp; end;<br><br>&nbsp;//result:=Bak1.Controls.Item[y].Caption;<br>&nbsp;//Bak1.Controls.Item[y].Caption:=Caption;<br>end;
 
在Word自创建"宏"来控制。
 
接受答案了.
 
后退
顶部