Bob,
You didn't post an e-mail address but maybe you're still scanning this
group...
I thought about this some more and realised that it might be possible to
write a macro to replace the field name exported by Outlook with one that
Word will recognise. I've only run simple tests etc.
Here's some VBA code for that. You can find more info on how to use it on
the Word MVP site at
http://word.mvps.org
NB, somewhere earlier in this thread I said that Outlook exports the data as
a Word document. But what it actually does is export it as a Unicode format
text file with a ".doc" extension.
Sub ModifyZipFieldName()
' Macro by PJ Jamieson, March 2004
' This macro looks for a field name called "ZIP/Postal Code"
' in the header record of a mail merge data source and modifies
' the name so that Word automatically maps its ZIP/Postal code
' to the field.
' Written for use with Word 2003/Outlook 2003, but it may work
' in earlier versions
' Requires the "Microsoft Scripting Runtime" object library:
' You will need to use the VBA Editor menu command
' Tools|References to add a reference to this library
' This macro is intended to be used when a merge is initiated
' from Outlook. In that case, I believe the following assumptions
' can be made:
' The merge data file is a Unicode format text file
' (notice that by default it has a .doc extension)
' Outlook reconnects to the data source and removes any
' sort/filter options you may have defined
' The macro also assumes that it is OK to create/overwrite a
' file with the same name as the data source + ".tmp"
Dim oFileSystemObject As Scripting.FileSystemObject
Dim oSourceStream As Scripting.TextStream
Dim oDestStream As Scripting.TextStream
Dim sHeaderRecord As String
Dim sMergeDataSourceName As String
Dim vMergeType As WdMailMergeMainDocType
Dim vMergeDestination As WdMailMergeDestination
On Error GoTo finish
With ActiveDocument.MailMerge
If .MainDocumentType = wdNotAMergeDocument Then
MsgBox "This document is not a mail merge main document"
Else
' Save merge type and destination
vMergeType = .MainDocumentType
vMergeDestination = .Destination
sMergeDataSourceName = .DataSource.Name
.MainDocumentType = wdNotAMergeDocument
Set oFileSystemObject = CreateObject("Scripting.FileSystemObject")
With oFileSystemObject
' This assumes the file is Unicode format (I think)
Set oSourceStream = .OpenTextFile( _
FileName:=sMergeDataSourceName, _
IOMode:=ForReading, _
Create:=False, _
Format:=TristateTrue)
' Verify that the required string exists before going any further
sHeaderRecord = oSourceStream.ReadLine
If InStr(1, sHeaderRecord, "ZIP/Postal Code") = 0 Then
MsgBox "Could not find the field name 'ZIP/Postal Code'" & _
"in the merge data source." & _
vbCrLf & "You will need to match fields manually"
oSourceStream.Close
Set oSourceStream = Nothing
Else
' create the output file
Set oDestStream = .CreateTextFile( _
FileName:=sMergeDataSourceName + ".tmp", _
overwrite:=True, _
unicode:=True)
' Make the substitution. The field names "ZIP" and "Postcode"
' seem to be recognised automatically by Word
oDestStream.WriteLine _
Text:=Replace(sHeaderRecord, "ZIP/Postal Code", "ZIP")
' copy the rest of the file
Do Until oSourceStream.AtEndOfStream
oDestStream.WriteLine Text:=oSourceStream.ReadLine
Loop
' Close everything and replace the old file by the new one
oDestStream.Close
Set oDestStream = Nothing
oSourceStream.Close
Set oSourceStream = Nothing
oFileSystemObject.DeleteFile _
filespec:=sMergeDataSourceName, _
force:=True
oFileSystemObject.MoveFile _
Source:=sMergeDataSourceName + ".tmp", _
Destination:=sMergeDataSourceName
End If
End With
Set oFileSystemObject = Nothing
End If
' Set up the mail merge data source etc. again
' You may find that you need to save and restore
' other settings
.OpenDataSource Name:=sMergeDataSourceName
.MainDocumentType = vMergeType
.Destination = vMergeDestination
End With
Exit Sub
finish:
Close #1
MsgBox "Error " & Err.Number & _
" when trying to modify the ZIP field name: " & _
vbCrLf & Err.Description
Err.Clear
On Error Resume Next
Set oSourceStream = Nothing
Set oDestStream = Nothing
Set oFileSystemObject = Nothing
End Sub