Solved

Running MS Word delphi application

Posted on 2000-02-23
4
264 Views
Last Modified: 2010-04-04
How do I run MS Word from my delphi program and open a given document automatically?
0
Comment
Question by:cjclayton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
4 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 100 total points
ID: 2552990
Hi
an example of opening and printing a document:

procedure TForm1.Button1Click(Sender: TObject);
const
  wdPrintAllDocument = $00000000;
  wdPrintDocumentContent = $00000000;
  wdPrintAllPages = $00000000;
var
WordApp : variant;
begin
try
WordApp := GetActiveOleObject('Word.Application');
except on exception do
WordApp := CreateOleObject('Word.Application');
end;
WordApp.wordbasic.fileopen('c:\test.doc');
WordApp.Visible := True;
WordApp.Wordbasic.EditBookmark('aBookmark', , , , -1);
WordApp.Wordbasic.insert(edit1.text);
WordApp.Wordbasic.insert(#13);
WordApp.PrintOut(FileName:='',
                 Range := wdPrintAllDocument,
                 Item := wdPrintDocumentContent,
                 Copies:=1,Pages:='',
                 PageType:=wdPrintAllPages,
                 Collate:=True,Background:=True,
                 PrintToFile:=False,PrintZoomColumn:=0,
                 PrintZoomRow:=0, PrintZoomPaperWidth:=0,
                 PrintZoomPaperHeight:=0);
  end;
end;

calls can depend on what version of word you have etc ..

see these links for better info:
there are tutorial (with code) about automating excel/word here:

http://hometown.aol.com/charliecal/TechPapers/DelphiWord.htm 

also a tutorial from borland:(see examples.zip for code)
http://www.inprise.nl/delphi/papers/microexcel/me3.html 

Regards Barry

0
 
LVL 17

Expert Comment

by:inthe
ID: 2552993
oops ,forgot to mention uses comobj;
0
 
LVL 17

Expert Comment

by:inthe
ID: 2552998
or can just open some document by doing:
 
add to uses shellapi;

then on button click what ever do:

ShellExecute(Application.Handle,'open',pchar('c:\someword.doc'),nil,nil,SW_SHOWNORMAL);
0
 
LVL 17

Expert Comment

by:inthe
ID: 2574660
hello ..do you get it to work ok?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

687 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