WD2001: Word 5.1 Mail Merge Document with Conditional IF Statement Converts Incorrectly (268435)



The information in this article applies to:

  • Microsoft Word 98 Macintosh Edition
  • Microsoft Word 2001 for Macintosh

This article was previously published under Q268435

SYMPTOMS

In Microsoft Word 2001, when you perform a mail merge using a document created in Microsoft Word 5.1, the mail merge operation may not function as expected. In the merged document, the information from the merged fields may be missing, and the document may contain an extra character ("1").

CAUSE

This behavior occurs if the conditional IF statement in Word 5.1 does not correctly convert to Word 2001.

WORKAROUND

To work around this issue, create a macro that does the following:
  1. Turns on the field codes.
  2. Replaces every instance of space=space1space ( = 1 ) with a single space ( ).
  3. Turns off the field codes.
  4. Selects the whole document.
  5. Updates the document so that the IF statements are updated.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site: For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site: The following sample macro can be used to repair the conditional IF statements that have been imported from a Word 5.1 document:
Sub fixfields()
    ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
    Application.DisplayStatusBar = True
    With ActiveWindow
        .DisplayHorizontalScrollBar = True
        .DisplayVerticalScrollBar = True
        .DisplayVerticalRuler = True
        .DisplayScreenTips = True
        With .View
            .ShowAnimation = True
            .ShowPicturePlaceHolders = False
            .ShowFieldCodes = True
            .ShowBookmarks = False
            .FieldShading = wdFieldShadingWhenSelected
            .ShowTabs = False
            .ShowSpaces = False
            .ShowParagraphs = False
            .ShowHyphens = False
            .ShowHiddenText = False
            .ShowAll = False
            .ShowDrawings = True
            .ShowObjectAnchors = False
            .ShowTextBoundaries = False
            .ShowHighlight = True
        End With
    End With
    Options.LiveWordCount = False
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = " = 1 "
        .Replacement.Text = " "
        .Forward = False
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
    Application.DisplayStatusBar = True
    With ActiveWindow
        .DisplayHorizontalScrollBar = True
        .DisplayVerticalScrollBar = True
        .DisplayVerticalRuler = True
        .DisplayScreenTips = True
        With .View
            .ShowAnimation = True
            .ShowPicturePlaceHolders = False
            .ShowFieldCodes = False
            .ShowBookmarks = False
            .FieldShading = wdFieldShadingWhenSelected
            .ShowTabs = False
            .ShowSpaces = False
            .ShowParagraphs = False
            .ShowHyphens = False
            .ShowHiddenText = False
            .ShowAll = False
            .ShowDrawings = True
            .ShowObjectAnchors = False
            .ShowTextBoundaries = False
            .ShowHighlight = True
        End With
    End With
    Options.LiveWordCount = False
    Selection.WholeStory
    ActiveWindow.ActivePane.LargeScroll Down:=-1
    Selection.Fields.Update
End Sub
				

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

To create a macro that updates all fields in a document or template, follow these steps:
  1. On the Tools menu, point to Macro, and then click Visual Basic Editor.
  2. In the Visual Basic Project window, expand the Project (Document/Template Name) folder.
  3. Double-click ThisDocument.
  4. In the Code window, type the code for either of the following macros.

    To run the macro when you open the document, type the following code:
    Sub AutoOpen()
       For Each aStory In ActiveDocument.StoryRanges
          aStory.Fields.Update
       Next aStory
    End Sub
    					

    -or-

    To run the macro when you create a new document, type the following code:
    Sub AutoNew()
       For Each aStory In ActiveDocument.StoryRanges
          aStory.Fields.Update
       Next aStory
    End Sub
    					
  5. On the File menu, click Save Document/Template Name.
  6. Close the Visual Basic Editor.
Each time you open or create a document, the macro runs and updates all fields in the document or template.

REFERENCES

For additional information about how to run sample code, click the article number below to view the article in the Microsoft Knowledge Base:

212536 OFF2000: How to Run Sample Code from Knowledge Base Articles

For additional information about getting help with Visual Basic for Applications, click the article number below to view the article in the Microsoft Knowledge Base:

226118 OFF2000: Programming Resources for Visual Basic for Applications


Modification Type:MajorLast Reviewed:8/29/2006
Keywords:kbbug kbnofix KB268435