Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / January 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
D Bernhardt - 07 Jan 2005 09:26 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.