Converting linked document objects to INCLUDETEXT fields

I have hundreds of small Word 2010 documents (i.e. one sentence in length) inserted in a larger "container" document. I inserted them using the command Insert | Object | Create From File. They are considered as "Linked Document Objects" when I right-click them.

 

For various reasons, a decision was subsequently made to replace all these linked document objects with INCLUDETEXT fields. Is there a way to convert the existing objects programmatically instead of deleting them and inserting the INCLUDETEXT fields one by one?

Thank you for any help you can provide!

Answer
Answer

The following macro should work. Try it on a copy of the original document and check the results before relying on it.

Sub ConvertLinkObjectsToIncludeText()
    Dim fld As Field
    Dim fname As String
    
    For Each fld In ActiveDocument.Fields
        If fld.Type = wdFieldLink Then
            fname = fld.LinkFormat.SourceFullName
            fname = Chr(34) & Replace(fname, "\", "\\") & Chr(34)
            fld.Code.Text = "INCLUDETEXT " & fname
            fld.Update
        End If
    Next
End Sub

_____________________________
https://jay-freedman.info

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 5, 2021 Views 241 Applies to: