Reply
 
Thread Tools Display Modes
  #1   Report Post  
Edwin Patrick
 
Posts: n/a
Default mail merge field names

How can I Loop through all the mail mertge fields in a document
and display the field Name?
  #2   Report Post  
Doug Robbins
 
Posts: n/a
Default

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.

--
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
"Edwin Patrick" wrote in message
...
How can I Loop through all the mail mertge fields in a document
and display the field Name?



  #3   Report Post  
Edwin Patrick
 
Posts: n/a
Default

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.

"Doug Robbins" wrote:

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.

--
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
"Edwin Patrick" wrote in message
...
How can I Loop through all the mail mertge fields in a document
and display the field Name?




  #4   Report Post  
Peter Jamieson
 
Posts: n/a
Default

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

"Edwin Patrick" wrote in message
...
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.

"Doug Robbins" wrote:

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.

--
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
"Edwin Patrick" wrote in message
...
How can I Loop through all the mail mertge fields in a document
and display the field Name?






  #5   Report Post  
Edwin Patrick
 
Posts: n/a
Default

Thanks a lot guys.
It worked.
many thanks.

"Peter Jamieson" wrote:

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

"Edwin Patrick" wrote in message
...
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.

"Doug Robbins" wrote:

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.

--
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
"Edwin Patrick" wrote in message
...
How can I Loop through all the mail mertge fields in a document
and display the field Name?








Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
mail merge with attachments AS Mailmerge 5 April 9th 05 09:49 AM
How do I mail merge to have different names on the main docume TonyM Mailmerge 1 January 26th 05 12:06 AM
Switch an image dynamically based on mail merge field - possible? Chris Hlusak Mailmerge 1 January 25th 05 12:11 AM
Mail Merge Field Stripping M. Johnson Mailmerge 3 January 12th 05 05:34 PM
How do I get a field to self adjust in a mail merge? DD Holt Mailmerge 1 December 29th 04 07:30 PM


All times are GMT +1. The time now is 10:07 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"