Automation MSWord from Delphi

Dear Sir,
I would like to control MSWord from Delphi. Using Variants is a simple way, but a bit slow. I am trying to get some information about the other way - through DispInterface using MSWord8.olb, which should be  performing the automation tasks a bit better.

I would really appreciate your help.

Best regards from
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

import type library is faster than variants.

Do the import, choose for create unit.

Do something like:
myWord: _Application;
myWord := CoApplication.Create;
myWord.Visible := True;
//maximize by handle, if you like:
hndl := FindWindow(PChar('OpusApp'), nil);
if hndl <> 0 then
   ShowWindow(hndl, SW_MAXIMIZE);

//new doc
Template := 'NORMAL.DOT';
NewTemplate := False;
myWord.Documents.Add(Template, NewTemplate);
//with some text

Well, it's a start. Hope I wrote correct code...:-)

zelenkaAuthor Commented:
Ok, what next?

How can I get a list of exported methods and properties? Is a documentation of a MSWOrd8.Olb available on the market?
To get a list you have to import that type libray in Delphi.

I don't have Delphi started at the moment... ..something like menu:
project | import type library | create unit.

Add this imported unit to your project uses list, and you can use all properties and methods.

As far as I know there's no complete documentation of some kind, just a lot of info on the internet.

How to know what to do:
record a macro in Word and do what you want to do. View the macro, find the methods in the imported library and rewrite the macro in Delphi.

Automating f.e. Word Perfect is easier, there's a tool called: OLE Command Inserter; translating your macro and inserting it into Delphi automatically. I never found something like that for Word, but thanslation macro's works.

Good luck,

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

by the by:

by importing a type library you could miss some functionality. For the most complete set of funtionality, you can use File | open and open a type library (f.e. .olb file) in the type library editor. I still do prefer an imported unnit.
What you can do is load Word up, click on the Tools|Macro and edit one, so that the VB editor appears.  From here you can pres F2 to see the objects and their properties.  You can use this to look at what you can access.



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
What would you like to do?

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.