VB:
http://www.cnblogs.com/yangbin1005/archive/2009/05/14/1456557.html
'激活单元格事件
Private Sub XL_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)
    MsgBox "XL_SheetSelectionChange"
End Sub
DELPHI:
http://borland.mblogger.cn/scyangyu/posts/15307.aspx我要在DELPHI下控制EXCEl,想控制EXCEL单元格选择的事件,就是无法实现,哪位可以帮助我。

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ComObj, Excel2000, OleServer;type
      TForm1 = class(TForm)
        Button1: TButton;
        Memo1: TMemo;
        procedure Button1Click(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        { Private declarations }
        procedure mySheetSelectionChange(ASender: TObject;
          const Sh: IDispatch; const Target: ExcelRange);
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      ww: TExcelWorkbook;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
            mExcel: IDispatch;
            Excelid: Variant;
            tt: _Application;
    begin
            try
                    mExcel:=CreateOleObject( 'Excel.Application' );
            except
                    on Exception do begin
                            ShowMessage('无法创建Xls文件,请确认是否安装EXCEL');
                            exit;
                    end;
            end;
            Excelid := mExcel;
            try
                    Excelid.WorkBooks.Open('d:\test.xls');
            except
                    on Exception do begin
                            ShowMessage('无法打开文件!');
                            exit;
                    end;
            end;        Excelid.Visible := True;        tt := nil;
            mExcel.QueryInterface(_Application,tt);
            ww := TExcelWorkbook.Create(nil);
            ww.ConnectTo(tt.ActiveWorkbook);
            ww.OnSheetSelectionChange := mySheetSelectionChange;
    end;procedure TForm1.mySheetSelectionChange(ASender: TObject;
          const Sh: IDispatch; const Target: ExcelRange);
    begin
            Memo1.Lines.Add(IntToStr(Target.Row) + ';' + IntToStr(Target.Column));
    end;procedure TForm1.FormDestroy(Sender: TObject);
    begin
            ww.Close;
            ww.Destroy;
    end;end.