Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Macro that unlinks the fields in a document, and then deletes itself

Macro that unlinks the fields in a document, and then deletes itself

Macro that unlinks the fields in a document, and then deletes itself

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
Set oRange = oRange.NextStoryRange
Loop Until oRange Is Nothing
End With

ThisDocument.VBProject.VBComponents.Remove _

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,

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".

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close