[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Fill Word Forms

Posted on 2004-10-18
7
Medium Priority
?
530 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 2000 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

Technology Partners: 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

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 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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

650 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