Solved

Running MS Word delphi application

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now