?
Solved

Running MS Word delphi application

Posted on 2000-02-23
4
Medium Priority
?
269 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 400 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

764 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