i'm trying to use MailMerge with Word 2010.
I have a TAB delimited file database.dat which looks like the following:
ID Name Street
1 John FooBar 1
2 Smith FooBar 2
This file is used in Word with the following VBA Code:
ActiveDocument.MailMerge.OpenDataSource Name:="C:/database.dat", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, Revert:=False, Format:=wdOpenFormatAuto
I can use the fields from the file now in the text. So everything works fine.
The Problem:
I need to do some further elaboration with the data in VBA, so I fetch the MergeField Value with:
Function getInfoField(mergefield As String)
On Error GoTo MergeFieldNotFound:
getInfoField = ActiveDocument.MailMerge.DataSource.DataFields(mergefield).Value
GoTo EndFunc
MergeFieldNotFound:
getInfoField = ""
EndFunc:
End Function
But if the length of a merge field value exceeds 255 characters it is cut off. So if I insert
MsgBox Len(ActiveDocument.MailMerge.DataSource.DataFields(mergefield).Value)
It outputs 255 for a String with e.g. 500 chars.
But directly in the word document, all 500 chars are shown for the merge field.
Question:
How can I get more than 255 chars out of the merge field in VBA?