Auto-deleting fields that generate an error

  • Thread starter christophercbrewster via OfficeKB.com
  • Start date
C

christophercbrewster via OfficeKB.com

I'm working on something that uses numerous DOCVARIABLE fields. I have a
macro to delete a docvariable that's no longer in use, and I want to do
something with any DOCVARIABLE fields that use the deleted docvariable. (I
haven't decided exactly what-- delete them, flag them, etc.) But I haven't
found a way to make my code find these fields and do something with them.
When I do a search-replace for "Error! No document variable supplied." and
replace with "", it gets rid of the displayed text, but the field is still
there. So when I update fields, I get the error text back. Does anyone have a
way to work with these?

--
Christopher Brewster
Lockheed Martin, Eagan MN

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200810/1
 
D

Doug Robbins - Word MVP

Use

Dim afield As Field
For Each afield In ActiveDocument.Fields
If afield.Result = "Error! No document variable supplied." Then
afield.Delete
End If
Next


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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