Sub Count_Selection()
Dim cell As Object
Dim count As Integer
count = 0
For Each cell In Selection
count = count + 1
Next cell
MsgBox count & " item(s) selected"
End Sub

解决方案 »

  1.   

    uses ActiveX;procedure TForm1.Button1Click(Sender: TObject);
    begin
      ExcelApplication1.Connect;
      ExcelApplication1.Workbooks.Add(EmptyParam, 0);
      ExcelApplication1.Visible[0] := True;
      (ExcelApplication1.Worksheets.Item[1] as _Worksheet).Range['E1', 'E5'].Select;
    end;procedure TForm1.Button2Click(Sender: TObject);
    var
      Enum: IEnumVariant;
      Selection: OleVariant;
      Application: OleVariant;
      Count: Integer;
      rgVar: OleVariant;
      vFetched: Longword;
    begin
      Application := ExcelApplication1.Application;
      Selection := Application.Selection;
      Enum:= IUnknown(Selection._NewEnum) as IEnumVariant;
      Count := 0;
      while Enum.Next(1, rgVar, vFetched) = S_OK do Inc(Count);
      ShowMessage(IntToStr(Count));
    end;
      

  2.   

    请问zswang(伴水清清)(专家门诊清洁工
    这个代码怎么转换?
    谢谢!
       For Each cell In Selection
            msgbox(cell.value)
       Next cell
      

  3.   

    while Enum.Next(1, rgVar, vFetched) = S_OK do
      begin
        ShowMessage(rgVar);
        Inc(Count);
      end;
      

  4.   

    谢谢,请问哪里有关于Delphi VBA方面的资料吗?书也行。
    受之以鱼不如受之议渔
    再谢