Solved

How to execute a word MACRO from Delphi?

Posted on 2003-11-11
7
1,153 Views
Last Modified: 2010-04-05
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
0
Comment
Question by:pvp1
  • 2
  • 2
7 Comments
 
LVL 6

Expert Comment

by:DaFox
Comment Utility
Hi PVP,

WordApplication1.Run('StartUp'); ??

Markus
0
 

Author Comment

by:pvp1
Comment Utility
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

0
 
LVL 6

Expert Comment

by:DaFox
Comment Utility
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
0
 

Author Comment

by:pvp1
Comment Utility
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
         

0
 
LVL 9

Accepted Solution

by:
tkalchev earned 50 total points
Comment Utility
Maybe you can try the following :


var WordApp : OleVariant;

WordApp := GetActiveOleObject ( 'Word.Application' );
WordApp.Run('StartUp');
WordApp := Unassigned;
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now