Solved

Running MS Word delphi application

Posted on 2000-02-23
4
260 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

Independent Software Vendors: 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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

732 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