Removing all formfields from Doc

Z

zSplash

What's the deal with this code? It errs when X = 6, although there are 9
FF's in the document.

Sub deleteFFs()
Dim X As Integer, tTotal As Integer
tTotal = ActiveDocument.FormFields.Count
For X = 1 To tTotal
ActiveDocument.FormFields(X).Delete
Next
End Sub

I tried writing something using "For each FF in ActiveDocument", but I don't
know how to loop without using names or indices. It must be tooooo
simple....

TIA
 
H

Helmut Weber

Hi,

having deleted formfields(1),
there are only 8 formfield left,
having deleted formfields(2),
there are only 7 formfields left ...
having deleted formfields(3),
there are only 6 formfields left ... ;-)

one possible way would be
to delete 9 times formfields(1).

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
H

Helmut Weber

Or delete them in reverse order, 9th first, 8th second, etc.?

That will work, too,
as well as deleting the first item in the collection,
but both methods will probably fail,
when deleting fields in the selection,
and there is a field right at the start of the selection.

If you want to know it all, see:

http://groups.google.de/group/micro...t+author:Weber&rnum=15&hl=de#998d7c1202e70a9a

Probably the same with fields as with hyperlinks.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
Z

zSplash

You guys are great. Thanks so much. (Seems so simple, once it's
explained....)

(used this code:
Do While ffCount > 0
ActiveDocument.Formfields(1).Delete
ffCount = ActiveDocument.Formfields.Count
Loop

st.
 

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