Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Recording a Macro on Excel via Delphi with OLE Automation

131 views
Skip to first unread message

Daniel Líberman

unread,
Jan 11, 2002, 6:55:48 AM1/11/02
to
Hi everybody,
I'm working with OLE Automation, accessing an Excel.Application OLE
Object through Delphi 5. I Had some problems trying to create a Chart some
times ago, and now... it's worst. Thanks to Tushar, his answer to my
questions worked fine. But the problem is different now, and... I really
don't
know how to proceed.
Well, I think there's how to resolve by another way. I'm trying to
record a Macro, and execute it from Delphi. But... I didn't find how to
record the macro, using the Excel.Application with OLE Automation. I
searched in VB Help, for the Application Object reference (for Excel), and
found the Method RecordMacro:

--
Records code if the macro recorder is on.
Syntax: expression.RecordMacro(BasicCode, XlmCode)
--

But... how can I turn on the macro recorder through Delphi? And give to
the macro a name, needed when I call it using the Run Method?

Thanks,
Daniel.

--
Daniel Valim Líberman dan...@ram.com.br
RAM Computer Systems www.ram.com.br

Fudiotes, desencatum.
Vita brevis...


Jesús Avilés Martínez

unread,
Jan 11, 2002, 6:32:52 AM1/11/02
to
Daniel Líberman wrote:

Hi,

See Deborah Pate´s page about automation. I think the answer is there:

http://www.djpate.freeserve.co.uk/Automation.htm

--
JAM - Relájate y disfruta...

Daniel Líberman

unread,
Jan 11, 2002, 10:03:17 AM1/11/02
to
>
> See Deborah Pate´s page about automation. I think the answer is there:
>
OK, I found a piece of code that should work, but... here ět is:
--
-- Deborah's code
--
uses
VBIDE97; // or VBIDE_TLB for Delphi 4
var
LineNo: integer;
CM: CodeModule;
begin
CM := WBk.VBProject.VBComponents.Item('ThisWorkbook').Codemodule;
LineNo := CM.CreateEventProc('Activate', 'Workbook');
CM.InsertLines(LineNo + 1, ' Range("A1").Value = "Workbook activated!"');

--
-- My code:
--
uses
VBIDE97;
var
vCodeModule: CodeModule;
//
// ...
//
pExcel := CreateOleObject ('Excel.Application');
vCodeModule := pExcel.ActiveWorkbook.VBProject.VBComponents.Item
('ThisWorkbook').CodeModule;

...... but in this last line there's an compilation error. The
method/property CodeModule (of Item('blabla') object) returns an Variant,
not a CodeModule (declared in VBI97, type of vCodeModule variable, which is
declared on my procedure). Incompatible types. And I couldn't apply a
typecast on this.

Well... I'll be searching more for some kind of solution...

Thanks for help.
[]s!

0 new messages