Vba for 'Field to plain text' [Shift][Ctrl][F9]

  • Thread starter D Bernhardt via OfficeKB.com
  • Start date
D

D Bernhardt via OfficeKB.com

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!
 
G

Greg

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
 
G

Greg

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

D Bernhardt via OfficeKB.com

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top