Hi!
Can anyone help me? How can I get hold of the VBA code for removing mergefields from a document and replacing it with plain text - Like when you use [Shift][Ctrl][F9]?
And a second part to the question - can one restrict the effect of this, so that { FORMTEXT } fields are not removed?
Thanks!
Greg - 07 Jan 2005 15:08 GMT
Try something like:
Sub ScratchMacro()
Dim oFld As Field
DocUnprotect
For Each oFld In ActiveDocument.Fields
If oFld.Type <> wdFieldFormTextInput Then
oFld.Unlink
End If
Next oFld
DocProtect
End Sub
Sub DocUnprotect()
On Error Resume Next
ActiveDocument.Unprotect
End Sub
Sub DocProtect()
On Error Resume Next
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub
D Bernhardt - 10 Jan 2005 11:00 GMT
Thanks! It works fine.
I have a question about how UNLINK works.
What happens if an {If else} field contains {Formtext} fields? Can one unlink the {If else} field while still keeping the contents as it is (linked)?
It seems as if when unlinking an {If else} field, the field and contents are unlinked as one object. Is there a way to UNLINK the contents while keeping the fields inside?
Thanks again!
Greg - 07 Jan 2005 15:08 GMT
Try something like:
Sub ScratchMacro()
Dim oFld As Field
DocUnprotect
For Each oFld In ActiveDocument.Fields
If oFld.Type <> wdFieldFormTextInput Then
oFld.Unlink
End If
Next oFld
DocProtect
End Sub
Sub DocUnprotect()
On Error Resume Next
ActiveDocument.Unprotect
End Sub
Sub DocProtect()
On Error Resume Next
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub