Re: Creating many letters(mail merge) from a single template in C#



Hi =?Utf-8?B?TWlrZTk5MDA=?=,

I need to fill up the letters without using any datasource.
For example, I already have a list of names, it does not access any db. This
is typical because the user selects a list from the list and says to create
mail.

If you don't have a data source, technically you can't use mail merge.

However, I understand that you and users decide to use the interface to insert
merge fields because it's there and one is familiar with it.

In this case, as a developer, you basically need to loop through all the fields
in the body of the document, extract the datafield name, look up the data and
insert it in place of the field.

Roughly, it would go like this (off the top of my head, so no guarantees on
the exact syntax):

Word.Document doc = WdApp.ActiveDocument
for each (Word.Field fld in doc.Fields)
{
if (fld.Type == wdApp.wdFieldType.wdFieldMergefield)
{
string sfldName = //Extract the field name, here, from the
fld.Code.Text
//Now look up the data
fld.Result.Text = "the data"
}
}

You'll need to look at the form fields the Word version your users have
generates in order to figure out how best to extract the information you need
for the field names.

Note that, because the data insertion could interfere with managing the Fields
collection, you might need to resort to a construct such as this, to loop all
the fields (VBA-speak):
For i = doc.Fields.Count to 0 Step -1

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)

.



Relevant Pages

  • Re: Publish Web Server behind SBS 2003 Standard
    ... Microsoft CSS Online Newsgroup Support ... When opening a new thread via the web interface, ... |> Method 2: Different ports ... |> "Network Connection". ...
    (microsoft.public.windows.server.sbs)
  • Re: SOLVED: lo0 not in ioctl( SIOCGIFCONF )
    ... bzero(ifr, sizeof(*ifr) * n); ... There are several problems with this loop. ... Yes, your algorithm is O), but allocating a larger ... interface and one per address so you to keep track of the last interface ...
    (freebsd-net)
  • RE: Page cannot be displayed in OWA
    ... But from the internet I cannot access the OWA or RWW ... This newsgroup only focuses on SBS technical issues. ... When opening a new thread via the web interface, ... | 25 to the external interface of the server ...
    (microsoft.public.windows.server.sbs)
  • Re: extract data from multiple Word forms into Excel
    ... Please reply to the newsgroup unless you wish to avail yourself of my ... > How do I extract data from a table? ... >> If you put all of the documents into a folder by themselves and then run ... >> Dim target As Document ...
    (microsoft.public.word.docmanagement)
  • RE: Client App Outlook 2003 SP1?
    ... the outlook 2003 for the SBS has some difference with normal ... the folder into which you want to extract the files. ... This newsgroup only focuses on SBS technical issues. ... you may want to contact Microsoft CSS directly. ...
    (microsoft.public.windows.server.sbs)