• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

Running MS Word delphi application

How do I run MS Word from my delphi program and open a given document automatically?
0
cjclayton
Asked:
cjclayton
  • 4
1 Solution
 
intheCommented:
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
 
intheCommented:
oops ,forgot to mention uses comobj;
0
 
intheCommented:
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
 
intheCommented:
hello ..do you get it to work ok?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now