uses activex,vbide97;
procedure TForm1.Button1Click(Sender: TObject);
var V:_VBComponent;
vArg1, vArg2, vArg3, vArg4, vArg5, vArg6, vArg7, vArg8, vArg9, vArg10,
vArg11, vArg12, vArg13, vArg14, vArg15, vArg16, vArg17, vArg18, vArg19, vArg20,
vArg21, vArg22, vArg23, vArg24, vArg25, vArg26, vArg27, vArg28, vArg29, vArg30: OLEVariant;
begin
vArg1:= EmptyParam; vArg2:= EmptyParam; vArg3:= EmptyParam; vArg4:= EmptyParam;
vArg5:= EmptyParam; vArg6:= EmptyParam; vArg7:= EmptyParam; vArg8:= EmptyParam;
vArg9:= EmptyParam; vArg10:= EmptyParam; vArg11:= EmptyParam; vArg12:= EmptyParam;
vArg13:= EmptyParam; vArg14:= EmptyParam; vArg15:= EmptyParam; vArg16:= EmptyParam;
vArg17:= EmptyParam; vArg18:= EmptyParam; vArg19:= EmptyParam; vArg20:= EmptyParam;
vArg21:= EmptyParam; vArg22:= EmptyParam; vArg23:= EmptyParam; vArg24:= EmptyParam;
vArg25:= EmptyParam; vArg26:= EmptyParam; vArg27:= EmptyParam; vArg28:= EmptyParam;
vArg29:= EmptyParam; vArg30:= EmptyParam;
self.ExcelApplication1.Connect;
ExcelApplication1.Workbooks.Add(null,0);
ExcelWorkBook1.ConnectTo(ExcelApplication1.WorkBooks.Item[1]);
V:=ExcelWorkBook1.VBProject.VBComponents.Add(TOleEnum($00000001));
V.name:='Module';
V.CodeModule.AddFromString('Public Sub test() '+#13+'msgbox("test") '+#13+'end sub');
ExcelApplication1.Visible[0] := True;
ExcelApplication1.Run('test',vArg1, vArg2, vArg3, vArg4, vArg5, vArg6, vArg7, vArg8, vArg9, vArg10,
vArg11, vArg12, vArg13, vArg14, vArg15, vArg16, vArg17, vArg18, vArg19, vArg20,
vArg21, vArg22, vArg23, vArg24, vArg25, vArg26, vArg27, vArg28, vArg29, vArg30);
end;
以上程序在excel中建立一个名为module的模块,并建立一个test的过程,并调用,d5下调试通过