Link to home
Start Free TrialLog in
Avatar of K Feening
K FeeningFlag for Australia

asked on

Mail Merge

I have an existing Word Document and want to merge line to specific positions in the letter

There is a Logo on the right side and below that on the left I need a Date Then Name Address then after the Section Probation Letter I need to add Dear XXXXX I dont want to insert lines, is there a way to add the information to a position in the Document without moving the existing letter down with inserts

Document -

Date:



[Given Name] [Surname]
[Address Line 1]
[Suburb] [State] [Postcode]

Probation Letter (Existing in Document)


Dear [Given Name],

Congratulations on the successful completion of your probation period
Avatar of John
John
Flag of Canada image

I put the fields in an Excel File with titles as you showed at the top of each row, create a basic letter and use the Word Mail Merge Wizard. It allow you to insert as need. The spacing of my letter does not change when I do this. Make sure your field is <....> with no spaces before or after.

The wizard allows you to check formatting and correct before completing the merge and printing.

... Thinkpads_User
Avatar of K Feening

ASKER

sorry This is done in Delphi using

// Create an instance of Word and make it visible
  wrdApp := CreateOleObject('Word.Application');
  wrdApp.Visible := True;
  // Create a new document
  wrdDoc := wrdApp.Documents.Add(fname);
  wrdDoc.Select;

  wrdSelection := wrdApp.Selection;
  wrdMailMerge := wrdDoc.MailMerge;

  // Create MailMerge data file
  CreateMailMergeDataFile;

  // Insert Merge Data
  wrdSelection.ParagraphFormat.Alignment := wdAlignParagraphLeft;
  wrdMergeFields := wrdMailMerge.Fields;
  InsertLines(10);
  wrdMergeFields.Add(wrdSelection.Range,'FirstName');
  wrdSelection.TypeText(' ');
  wrdMergeFields.Add(wrdSelection.Range,'LastName');
  wrdSelection.TypeParagraph;
  wrdMergeFields.Add(wrdSelection.Range,'Address');
  wrdSelection.TypeParagraph;
  wrdMergeFields.Add(wrdSelection.Range,'City');
  InsertLines(2);
  wrdSelection.ParagraphFormat.Alignment := wdAlignParagraphJustify;
  wrdSelection.TypeText('Dear ');
  wrdMergeFields.Add(wrdSelection.Range,'FirstName');
  wrdSelection.TypeText(' ');
  InsertLines(1);
Just a suggestion.
Use some reporting tools to create resulting form. Save it as .pdf format. IMHO  more preferable way in email then  MS Word document.
Sorry I don't understand it's not an email and they don't want a pdf file its a Form letter to selected staff from a Interbase Database I insert the name Address from then database into the existing MS Word document and then they print and post to the staff. I need to know if you can insert the name address and Dear XXXXXX in specific spots in the MS Word Document without the existing information moving from its origional saved Word Document position.

Thanks
So, place variables in existing MS Word document, then assign data to that variables in your application.
How do you add variables using MS Word and how to you assign data to them or find them using Delphi
ASKER CERTIFIED SOLUTION
Avatar of Igor UL7AAjr
Igor UL7AAjr
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks tried the example but it has problems is it the same code for Delphi