CookingFat
Technical User
Hi all,
The following macro unlinks the fields in a document, and then deletes itself:
--------------------------
Sub UnlinkFields()
Dim oRange As Word.Range
With ActiveDocument
For Each oRange In .StoryRanges
Do
oRange.Fields.Unlink
Set oRange = oRange.NextStoryRange
Loop Until oRange Is Nothing
Next
End With
ThisDocument.VBProject.VBComponents.Remove _
ThisDocument.VBProject.VBComponents("NewMacros")
End Sub
--------------------------
The document is "read-only". The idea is that I'd run the above macro, then save the document as a new document, and then when I email the (new) document to someone else they'd receive a document that 1) doesn't contain any fields, 2) doesn't contain any macros, and 3) isn't attached to any template.
However, does anyone know if it's possible to modify the above macro so that it unlinks the fields only within the text boxes in the document? The issue is that, for this particular document, the text boxes contain fields that are linked to an Excel spreadsheet (which I want to unlink and replace with text), but the remaining parts of the document contain a standard hyperlink and a mailto link (which I don't want to replace with text).
Thanks very much,
Steve
Edit: I should've mentioned that the part of the above macro that deletes itself requires the following "Macro Security" option to be ticked; "Trust access to the VBA project object module".
The following macro unlinks the fields in a document, and then deletes itself:
--------------------------
Sub UnlinkFields()
Dim oRange As Word.Range
With ActiveDocument
For Each oRange In .StoryRanges
Do
oRange.Fields.Unlink
Set oRange = oRange.NextStoryRange
Loop Until oRange Is Nothing
Next
End With
ThisDocument.VBProject.VBComponents.Remove _
ThisDocument.VBProject.VBComponents("NewMacros")
End Sub
--------------------------
The document is "read-only". The idea is that I'd run the above macro, then save the document as a new document, and then when I email the (new) document to someone else they'd receive a document that 1) doesn't contain any fields, 2) doesn't contain any macros, and 3) isn't attached to any template.
However, does anyone know if it's possible to modify the above macro so that it unlinks the fields only within the text boxes in the document? The issue is that, for this particular document, the text boxes contain fields that are linked to an Excel spreadsheet (which I want to unlink and replace with text), but the remaining parts of the document contain a standard hyperlink and a mailto link (which I don't want to replace with text).
Thanks very much,
Steve
Edit: I should've mentioned that the part of the above macro that deletes itself requires the following "Macro Security" option to be ticked; "Trust access to the VBA project object module".