Reply
 
Thread Tools Display Modes
  #1   Report Post  
Michael Krause
 
Posts: n/a
Default Outlook -> Word Mailmerge defaults question - Zipcode missing from Addressblock

As the subject says, I'm using Outlook 2003 to export into Word 2003. Using
the Tools/Mail merge in Outlook, I bring the contacts into Word. Then using
the Mail merge wizard in Word, by *default* the postal code field is left
out when I use the 'Addressblock' reference in my label.

To fix this, I obviously need to match fields. But this seems to be a
prevalent issue with every install of Office I've worked with. Is there an
explanation why the Zipcode/Postalcode field does not automatically match
with respect to the Addressblock?

I want this thing to default so addressblock works fine within my merge in
Word without manually referencing ZipPostalcode (or whatever the field is
called) in 'Match Fields'.

Is it possible to default?


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

The only way I have found to do this is to fix the field name in the Word
document that Outlook exports when you initiate your merge from Oulook
(assuming that's what you're doing. I wrote the following code a while ago
and you would probably have to create a toolbar button and run it manually
once Outlook has opened the merge main document.

For more background info you might be able to follow this link or search in
Google groups for, e.g. jamieson vba zip map fields scripting

http://groups-beta.google.com/group/...b9 8f943986bb

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
Peter Jamieson

"Michael Krause" wrote in message
...
As the subject says, I'm using Outlook 2003 to export into Word 2003.
Using the Tools/Mail merge in Outlook, I bring the contacts into Word.
Then using the Mail merge wizard in Word, by *default* the postal code
field is left out when I use the 'Addressblock' reference in my label.

To fix this, I obviously need to match fields. But this seems to be a
prevalent issue with every install of Office I've worked with. Is there
an explanation why the Zipcode/Postalcode field does not automatically
match with respect to the Addressblock?

I want this thing to default so addressblock works fine within my merge in
Word without manually referencing ZipPostalcode (or whatever the field is
called) in 'Match Fields'.

Is it possible to default?



  #3   Report Post  
Michael Krause
 
Posts: n/a
Default

Thanks for the reply, and the script. So the simple answer is that Microsoft
didn't set the field names to match between Microsoft Word and Outlook, thus
explaining the discrepency requiring manual intervention.

"Peter Jamieson" wrote in message
...
The only way I have found to do this is to fix the field name in the Word
document that Outlook exports when you initiate your merge from Oulook
(assuming that's what you're doing. I wrote the following code a while ago
and you would probably have to create a toolbar button and run it manually
once Outlook has opened the merge main document.

For more background info you might be able to follow this link or search
in Google groups for, e.g. jamieson vba zip map fields scripting


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

I'd prefer a slightly less simple answer, e.g. that in the English language
version of Office, Microsoft did not ensure that the field name generated by
Outlook's Mail merge option would be automatically matched in Word. I have
no idea why they did not get this right in the first place and why they have
not fixed it either in Word 2003 or one of the SPs. It would be interesting
to know whether the same problem occurs in other language versions of
Office.

Peter Jamieson

"Michael Krause" wrote in message
...
Thanks for the reply, and the script. So the simple answer is that
Microsoft didn't set the field names to match between Microsoft Word and
Outlook, thus explaining the discrepency requiring manual intervention.

"Peter Jamieson" wrote in message
...
The only way I have found to do this is to fix the field name in the Word
document that Outlook exports when you initiate your merge from Oulook
(assuming that's what you're doing. I wrote the following code a while
ago and you would probably have to create a toolbar button and run it
manually once Outlook has opened the merge main document.

For more background info you might be able to follow this link or search
in Google groups for, e.g. jamieson vba zip map fields scripting




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
In typing dates in Word, i.e. "January 12" how do you keep the "1. Carol Microsoft Word Help 2 January 12th 05 09:09 PM
word xp crashes after macros are recorded kharris0405 Microsoft Word Help 3 January 11th 05 11:50 PM
WP Delay Code - Word Equiv Mike G - Milw, WI Microsoft Word Help 6 January 10th 05 05:12 PM
How to change merge forms from Word Perfect to Microsoft Word dollfindance Microsoft Word Help 2 December 30th 04 04:35 PM
macro in word js Microsoft Word Help 1 December 28th 04 04:01 AM


All times are GMT +1. The time now is 12:12 AM.

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"