Converting FormFields to plain text?

T

Tsu Dho Nimh

OK:

Unlinking doesn't work ... it resets the fields.

Help file makes no mention of how to do it it, because
apparently MSFT doesn't think it's necessary.

But I need to do this.

Anyone have a method?



Tsu Dho Nimh
 
J

Jean-Guy Marcil

Hi Tsu Doh,

Have you tried:

Unprotect the document,
CTRL-A;
SHIFT-CTRL-F9;
CTRL-HOME.

Or, with a macro:

ActiveDocument.Unprotect
ActiveDocument.Range.Fields.Unlink

That works on my computer (Windows & Office XP)..

--
Cheers!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
P

Peter Hewett

Hi

This will do what you want:

Sub UnlinkFormFields()
Dim ffItem As Word.FormField
Dim rngStory As Word.Range
Dim lngIndex As Long

' Since we're unlinking FormFields assume documents protected
ActiveDocument.Unprotect

' Iterate through all story types
For Each rngStory In ActiveDocument.StoryRanges

Do Until rngStory Is Nothing

' Do this backwards as we are using the FormFields
' index and deleteing FormFields from the same collection
' at the same time
For lngIndex = rngStory.FormFields.Count To 1 Step -1

' Unlink the FormField
Set ffItem = rngStory.FormFields(lngIndex)
ffItem.Range.Text = ffItem.Result
Next

' There may be linked stories so make sure we get them as well
Set rngStory = rngStory.NextStoryRange
Loop
Next

' Since the documents no longer got any FormFields in it there
' doesn't seem much point in protecting the document again!
End Sub

HTH + Cheers - Peter
 
P

Peter Hewett

Hi

Sorry the last piece of code I posted was adapted from a version that works
with other fields. Consequently it was not very succinct, here's a shorter
version:

Sub UnlinkFormFields()
Dim ffItem As Word.FormField
Dim lngIndex As Long

' Since we're unlinking FormFields assume documents protected
ActiveDocument.Unprotect

' Do this backwards as we are using the fields
' index and deleteing fields from the same collection at
' the same time
For lngIndex = ActiveDocument.Content.FormFields.Count To 1 Step -1

' Unlink the FormField
Set ffItem = ActiveDocument.Content.FormFields(lngIndex)
ffItem.Range.Text = ffItem.Result
Next

' Since the documents no longer got any FormFields in it there
' doesn't seem much point in protecting the document again!
End Sub

HTH - Cheers - Peter
 

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