Link to home
Start Free TrialLog in
Avatar of pvp1
pvp1

asked on

How to execute a word MACRO from Delphi?

Hello All,

           My application is having a OLE continer with a word document as an object. I have created a Word Macro called 'StartUp'. I have to execute this Macro when the word document(Oleobject) is active.

          I tried to execute it like:
                        Olecontiner1.Oleobject.RunMacro('StartUp');
-- But the method RunMacro is not recognized by Delphi.

Could you provide me a suggestion how to execute a macro from Delphi?

Thanks
PVP
Avatar of DaFox
DaFox

Hi PVP,

WordApplication1.Run('StartUp'); ??

Markus
Avatar of pvp1

ASKER

Hello Markus!

          With this statement i had a runtime exception. WordObject(OleContinerObject) can not support the Method 'Run' !!!  Is there any method which can support OleObject?

thanks
pvp

Don't know, maybe you first have to add the template to the list of templates for the current session.

oleContainer1.OleObject.application.AddIns.Add('C:\{...}StartUp.dot', true);
and after that
application.run("StartUp");

But I'm not really sure about it; just try it ;0)

Markus
Avatar of pvp1

ASKER

Hello,
     
i tried directly like ..
        oleContainer1.OleObject.application.run('StartUp');

it is able to start executing the Macro, StartUp... but immediately i am getting the runtime error :
           Microsoft Visual Basic, Runtime error: 4605
                      'Thsi method or property is not available because this document is in another application'

could anybody help how to solve this problem?

Thanks
pvp
         

ASKER CERTIFIED SOLUTION
Avatar of tkalchev
tkalchev
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial