Solved

Fill Word Forms

Posted on 2004-10-18
7
527 Views
Last Modified: 2010-04-05
Hi,

I'm writing a Little Delphi App that has to take in the command line some arguments and from that fill a predefined word form. What I can't seem to do is to have access to those form fields. I tried through Bookmarks, but the only thing it does is overwrite my field and replacing it with my text. Here is a code snippet:

procedure TForm1.Button2Click(Sender: TObject);
begin

     Name := txtNom.Text + txtPrenom.Text;
     WordApp1 := CreateOleObject('Word.Application');
     WordApp1.Visible := False;
     WordApp1.Documents.Open('c:\DossierTemplate.doc');
     WordApp1.Selection.Find.ClearFormatting;
     WordApp1.Selection.Find.Replacement.ClearFormatting;
     WordApp1.Selection.Find.Execute('<NAME>',True,False,False,False,False,True,1,False,Name,2);

     WordApp1.Selection.Find.ClearFormatting;
     WordApp1.Selection.Find.Replacement.ClearFormatting;
     WordApp1.Selection.Find.Execute('<ADRESSE>',True,False,False,False,False,True,1,False,txtAdresse.Text,2);
     WordApp1.ActiveDocument.Bookmarks.Item('SomeText').Range.Text := txtAdresse.Text;

     WordApp1.ActiveDocument.SaveAs('c:\NewDoc.doc');

What I need to have is code to fill-in the fields and not replace them.

Thanks
0
Comment
Question by:dabitbol
[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
  • 3
  • 3
7 Comments
 
LVL 6

Expert Comment

by:vadim_ti
ID: 12339700
i tried your code with template built as

.........
........
Name: <NAME>
Address: <ADDRESSE>
........
........

after running your code i get

.........
........
Name: TxtNomTxtPrenom
Address: txtAdresse
........
........

what exactly you wanted to get?
0
 
LVL 3

Author Comment

by:dabitbol
ID: 12340327
On this solution I used manual tags to position the text I wanted to replace. This worked fine. However, now our forms use fill-in fields so placing Tags is not an option because I need to have form fields and because I might need to modify the form later.

Basically I need to know where in the Word DOM are the form fields and how to access them programatically with an example if possible.

Thanks
0
 
LVL 3

Expert Comment

by:danielluyo
ID: 12341254
you can access the fields in the document using:

Documents(1).Fields(1).Result.Text = "my text"

0
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!

 
LVL 3

Author Comment

by:dabitbol
ID: 12341270
not in COM nor in Delphi

David
0
 
LVL 3

Accepted Solution

by:
danielluyo earned 500 total points
ID: 12341449
procedure TForm1.Button1Click(Sender: TObject);
var
    WordApp1, WordDoc, WordField: Variant;
begin
    WordApp1 := CreateOleObject('Word.Application');
    WordApp1.Visible := False;
    WordDoc := WordApp1.Documents.Open('c:\Testformulario.doc');
    WordField := WordDoc.Fields.Item(1);
    WordField.Result.Text := 'myNew Text';
    WordApp1.ActiveDocument.SaveAs('c:\NewDoc.doc');
end;
0
 
LVL 3

Author Comment

by:dabitbol
ID: 12341479
Found it by myself, but I'll give you the point DanielLuyo since you were right.

David
0
 
LVL 3

Expert Comment

by:danielluyo
ID: 12341498
thanks : )
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

726 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