Share via

Unlinking fields

Anonymous
2018-10-31T00:19:00+00:00

I automate a merge from msaccess to a word template. The template has :

  • {mergefield} codes for data fields in the msaccess database
  • {includetext} fields for subdocuments that plug into the tempate
  • {seq} codes for numbered lists.

When the merge completes, my vba code currently unlinks all fields so that the {mergefield} codes and {includetext) docs are no longer linked to the resulting Word document.  However, I do not want to unlink the {seq} fields.  The user may wish to add/delete lists/items from the resulting document, and of course, I don't want them to lose the feature of the auto re-numbering sequences.

I am currently using these commands to unlink all fields in the document. However, I don't want to unlink {seq} fields:

       Selection.wholeStory

       Selection.Fields.unlink

How can I keep word from unlinking the {seq} fields, while still unlinking the {mergefield} and {includetxt} fields?

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Paul Edstein 82,861 Reputation points Volunteer Moderator
2018-10-31T04:03:27+00:00

You don't need any VBA code for this! Simply embed your INCLUDETEXT field in a QUOTE field. For example:

{QUOTE{INCLUDETEXT C:\Path\Filename}}

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

17 additional answers

Sort by: Most helpful
  1. Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
    2018-10-31T02:47:13+00:00

    As you do not want to unlink the SEQ fields, Charles' code should have been:

    Sub SomeFieldsUnlinkAllStory()

    '   Written by Charles Kyle Kenyon 30 October 2018

    '   help from Jezebel

    '   All Story Date Field Unlinker

        Dim oField As Field

        Dim oStory As range

    '    On Error Resume Next

        For Each oStory In ActiveDocument.StoryRanges

        ' This goes into headers and footers as well as the regular document

            Do

                For Each oField In oStory.Fields

                    If oField.Type = wdFieldMergeField Or oField.type = wdFieldIncludeText Then

                        oField.Unlink

                    End If

                Next oField

                Set oStory = oStory.NextStoryRange

            Loop Until oStory Is Nothing

        Next oStory

    End Sub

    Of course, if your code was actually executing the merge, there would be no need to unlink the merge fields.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2018-10-31T11:06:13+00:00

    Anything inside a QUOTE field will be unlinked during the merge; likewise if you use an IF field.

    Was this answer helpful?

    0 comments No comments
  3. Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
    2018-10-31T09:42:57+00:00

    Hi Paul,

    Does that rely on the merge actually being executed, which is probably not the case as it appears that there is a need to unlink the MergeFields?

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2018-10-31T01:11:12+00:00

    Hi Karen,

    First, your macro will not reach all fields.

    Here is one that should do what you want.

    Sub SomeFieldsUnlinkAllStory()
    '   Written by Charles Kyle Kenyon 30 October 2018
    '   help from Jezebel
    '   All Story Date Field Unlinker
        Dim oField As Field
        Dim oStory As range
    '    On Error Resume Next
        For Each oStory In ActiveDocument.StoryRanges
        ' This goes into headers and footers as well as the regular document
            Do
                For Each oField In oStory.Fields
                    If oField.Type = wdFieldMergeField Then
                        oField.Unlink
                    End If
                    If oField.Type = wdFieldSequence Then
                        oField.Unlink
                    End If
                Next oField
                Set oStory = oStory.NextStoryRange
            Loop Until oStory Is Nothing
        Next oStory
    End Sub
    

    I hope this information helps. Please let me know if you have any more questions or require further help.

    Regards

    Was this answer helpful?

    0 comments No comments