How to add a mergefield to a blank document via visual basic

F

fledeboer

Hello,

I am trying to write an add-in with visual studio 2008 (visual basic) for
Word2007 to let users build a mailmerg document template. In the second steo
these mergefields should handle values from an active directory. To do this I
would like to have a ribbongroup with some buttons in it. By pressing a
button a mail merge field e.g. {MERGEFIELD firstname} should be inserted at
the current cursor position.

I don't know how to use the Filed.Add method. Maybe someone has an example
for me?
 
D

Doug Robbins - Word MVP on news.microsoft.com

Use:

ActiveDocument.Fields.Add Selection.Range, wdFieldEmpty, "Mergefield
FirstName"


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top