Solved

Delphi and MS Word 2000

Posted on 2003-10-30
5
733 Views
Last Modified: 2011-08-18
Hello,

I am working on a Delphi program that creates word document and writes to the document. I am using Delphi 5.0 and MS Word 2000 programs. I am able to create a blank document but not able to write anything to it .... Everytime I do, I get access violation.


PLEASEEEEEEEEEEEEE HELP

Sample code or actual code that I can use and practice on that writes to the document would be a great help thanks.
0
Comment
Question by:Digitalanolog1
5 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 500 total points
ID: 9656352
Hi,

Try this:

uses ComObj;

procedure TForm1.Button1Click(Sender: TObject);
var
  WordApp, WordDoc: OLEVariant;
begin
 WordApp := CreateOleObject('Word.Application');
 WordApp.Visible := True; // show MS Word
 WordApp.Caption:='Winword From Delphi';
 // to open an existing doc
 // WordDoc:=WordApp.Documents.Open('Letter.dot');
 // to create new doc
 WordDoc:=WordApp.Documents.Add;
 WordDoc.Paragraphs.Item(1).Range.Bold :=True;
 WordDoc.Paragraphs.Item(1).Range.Font.Size :=30;
 WordDoc.Paragraphs.Item(1).Range.Font.Name:='Tahoma';
 WordDoc.Paragraphs.Item(1).Range.Text:= 'Welcome To Delphi World';
 // save the doc
 WordDoc.SaveAs('c:\mydoc.doc');
 // print the doc
 // WordDoc.PrintOut;
 WordDoc.Close; // closes the current document
 WordApp.Quit; // exits MS Word
end;

Regards, Geo
0
 
LVL 5

Expert Comment

by:DeerBear
ID: 9659685
Hi,

To do what you want, I would use Server components in the
Delphi palette( yes, there's the updated version for D5 too ).

I would only use them for testing, though, since if you use them in
production code your app will be bound to that specific Word version.

HTH,

Andrew
0
 

Author Comment

by:Digitalanolog1
ID: 9662801
Hi Geo,

does your sample code work with any version of MS word program? Oh by the way your code works.

:) thanks man

0
 
LVL 17

Expert Comment

by:geobul
ID: 9669462
Hi,

It works with MS Word 97 and 2000. It should work with XP also but I haven't tried that yet.

Regards, Geo
0
 

Expert Comment

by:alvictor
ID: 10012364
Hello guys.

I am working with Delphi and Word just like you seem to work. But the difference is that I'm not working with desktop application, but ActiveX Components embed into web pages.

Until now I was able to use the TOleContainer just fine, I can let the user edit and modify the document. But when I need to automate the changes, using the TWordApplication component (coding just like as coding for desktop applications), it just doesn't work. I've tried several differents implementations, but every one of them give me an unespecified error message.

Do you know if there are some limitations of using ActiveX Components such as these into web pages???

Thanks a lot.
- Al Victor.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

786 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