Mail Merge

Posted on 2012-09-13
Last Modified: 2012-10-09
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 -


[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
Question by:Kevinfeening
    LVL 89

    Expert Comment

    by:John Hurst
    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

    Author Comment

    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);

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

      // Create MailMerge data file

      // Insert Merge Data
      wrdSelection.ParagraphFormat.Alignment := wdAlignParagraphLeft;
      wrdMergeFields := wrdMailMerge.Fields;
      wrdSelection.TypeText(' ');
      wrdSelection.ParagraphFormat.Alignment := wdAlignParagraphJustify;
      wrdSelection.TypeText('Dear ');
      wrdSelection.TypeText(' ');
    LVL 9

    Expert Comment

    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.

    Author Comment

    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.

    LVL 9

    Expert Comment

    So, place variables in existing MS Word document, then assign data to that variables in your application.

    Author Comment

    How do you add variables using MS Word and how to you assign data to them or find them using Delphi
    LVL 9

    Accepted Solution

    Way to go:
    How to store and retrieve variables in Word documents

    Author Comment

    Thanks tried the example but it has problems is it the same code for Delphi

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This very simple solution applies to a narrow cross-section of the "needs to close" variety. In this case, the full message in Event Viewer was in applog, Event ID 1000: Faulting application iexplore.exe, version 8.0.6001.18702, faulting module …
    Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
    The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
    The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

    734 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

    27 Experts available now in Live!

    Get 1:1 Help Now