来自: hsgrass, 时间: 2006/06/16 14:27:54, ID: 3473070 <br>// 详细使用查询VBA手册 <br>unit Unit2; <br><br>interface <br><br>uses <br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, <br> Dialogs, StdCtrls; <br><br>type <br> TForm2 = class(TForm) <br> btn1: TButton; <br> btn2: TButton; <br> procedure btn1Click(Sender: TObject); <br> procedure FormCreate(Sender: TObject); <br> procedure FormDestroy(Sender: TObject); <br> private <br> { Private declarations } <br> public <br> { Public declarations } <br> end; <br><br>var <br> Form2: TForm2; <br> excel: Variant; <br>implementation <br><br>uses ComObj; <br><br><br><br>{$R *.dfm} <br><br>procedure TForm2.btn1Click(Sender: TObject); <br>begin <br>excel.Workbooks.add(); <br>excel.visible := true; <br>excel.ActiveSheet.Protect(); <br>end; <br><br>procedure TForm2.FormCreate(Sender: TObject); <br>begin <br>excel := CreateOleObject('Excel.Application'); <br>end; <br><br>procedure TForm2.FormDestroy(Sender: TObject); <br>begin <br> Excel := null; <br>end; <br><br>end. <br>---------------------------------- <br>保护工作表使其不至被修改。