[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to execute a word MACRO from Delphi?

Posted on 2003-11-11
7
Medium Priority
?
1,325 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
5 Comments
 
LVL 6

Expert Comment

by:DaFox
ID: 9724912
Hi PVP,

WordApplication1.Run('StartUp'); ??

Markus
0
 

Author Comment

by:pvp1
ID: 9724975
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
ID: 9725122
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
ID: 9730039
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 200 total points
ID: 9741040
Maybe you can try the following :


var WordApp : OleVariant;

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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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 shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month18 days, 10 hours left to enroll

834 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