A family of Microsoft word processing software products for creating web, email, and print documents.
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}}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I automate a merge from msaccess to a word template. The template has :
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?
A family of Microsoft word processing software products for creating web, email, and print documents.
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.
Answer accepted by question author
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}}
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.
Anything inside a QUOTE field will be unlinked during the merge; likewise if you use an IF field.
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?
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