首页  编辑  

Word中屏蔽某些按键

Tags: /超级猛料/Office.OA自动化/Word/   Date Created:

Word 中屏蔽某些按键

uses Office2000;

procedure TForm1.Button1Click(Sender: TObject);

var

 vVisible: OleVariant;

 vCommandBarControls: CommandBarControls;

 I: Integer;

 vArg: OleVariant;

 vKeyBinding: KeyBinding;

begin

 WordApplication1.Connect;

 WordApplication1.Visible := True;

 vVisible := True;

 WordApplication1.Documents.Add(EmptyParam, EmptyParam, EmptyParam, vVisible);

 vCommandBarControls := WordApplication1.CommandBars.FindControls(

   EmptyParam, 4, EmptyParam, EmptyParam);

 for I := 1 to vCommandBarControls.Count do

   vCommandBarControls.Item[I].Set_Visible(False);

 vArg := wdKeyControl;

 vKeyBinding := WordApplication1.FindKey[WordApplication1.BuildKeyCode(wdKeyP, vArg),

   EmptyParam];

 if Assigned(vKeyBinding) then vKeyBinding.Disable;

end;

procedure TForm1.Button2Click(Sender: TObject);

var

 vArg: OleVariant;

 vKeyBinding: KeyBinding;

begin // 还原

 vArg := wdKeyControl;

 vKeyBinding := WordApplication1.FindKey[WordApplication1.BuildKeyCode(wdKeyP, vArg),

   EmptyParam];

 if Assigned(vKeyBinding) then vKeyBinding.Clear;

end;