Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / March 2005

Tip: Looking for answers? Try searching our database.

mail merge field names

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Edwin Patrick - 08 Mar 2005 18:17 GMT
How can I Loop through all the mail mertge fields in a document
and display the field Name?
Doug Robbins - 08 Mar 2005 23:49 GMT
Dim af As Field
For Each af In ActiveDocument.Fields
If af.Type = wdFieldMergeField Then
   MsgBox af.Code
End If
Next af

Use the Mid() function to get rid of the MERGEFIELD if you don't want to
display it.

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> How can I Loop through all the mail mertge fields in a document
> and display the field Name?
Edwin Patrick - 09 Mar 2005 16:25 GMT
Thanks for your help.
But I do not get the field name I get a error message at the line "msgbox
af.code" since code is a field type of "Range".
I am still in the same problem now.
All I need to do is to loop through all the merge fields in the
word document and create an array and replace the mergefields with the
values I get from the database.
Any suggestion will be of great help.

> Dim af As Field
> For Each af In ActiveDocument.Fields
[quoted text clipped - 8 lines]
> > How can I Loop through all the mail mertge fields in a document
> > and display the field Name?
Peter Jamieson - 09 Mar 2005 17:33 GMT
Try

af.Code.Text

But you will have to strip off the MERGEFIELD, white space, and any quotes
to get the name of the field, and it may not match the one in the data
source if, for example, the data source has field names longer than around
32 characters. And so on...

Peter Jamieson

> Thanks for your help.
> But I do not get the field name I get a error message at the line "msgbox
[quoted text clipped - 17 lines]
>> > How can I Loop through all the mail mertge fields in a document
>> > and display the field Name?
Edwin Patrick - 09 Mar 2005 22:57 GMT
Thanks a lot guys.
It worked.
many thanks.

> Try
>
[quoted text clipped - 28 lines]
> >> > How can I Loop through all the mail mertge fields in a document
> >> > and display the field Name?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.