Home |
Search |
Today's Posts |
#1
|
|||
|
|||
mail merge field names
How can I Loop through all the mail mertge fields in a document
and display the field Name? |
#2
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
mail merge with attachments | Mailmerge | |||
How do I mail merge to have different names on the main docume | Mailmerge | |||
Switch an image dynamically based on mail merge field - possible? | Mailmerge | |||
Mail Merge Field Stripping | Mailmerge | |||
How do I get a field to self adjust in a mail merge? | Mailmerge |