Identify a formula field

S

singeredel

I have code to delete bookmarks and unlink fields in a document once the
document is completed, as follows:

For Each Mark In .Bookmarks
.Bookmarks(Mark).Delete
Next Mark
For Each Field In .Fields
.Fields.Unlink
Next Field
End With

I need to NOT unlink a field if it contains a formula, only unlink the field
if it is a bookmark type field, but I don't know how to write this code.

Thanks for any help.
 
S

singeredel

If anyone can please still help me further with this. I can't figure out how
to identify whether the field contains a formula, in which case I do not want
to unlink the field (which is within a table). I have tried the following,
which does not work:

With Documents(CurrentDocument)
If Not wdFieldFormula Then
For Each Field In .Fields
.Fields.Unlink
Next Field
End If
End With


Thanks.
 
R

Russ

Singeredel,
If anyone can please still help me further with this. I can't figure out how
to identify whether the field contains a formula, in which case I do not want
to unlink the field (which is within a table). I have tried the following,
which does not work:

With Documents(CurrentDocument)
If Not wdFieldFormula Then
For Each Field In .Fields
.Fields.Unlink
Next Field
End If
End With

Your pseudo code looks like it is checking whether the whole document is one
big Field Formula; and if not, then unlinking all fields within it. Is that
what you wanted to logically happen with your code?
Or do you want to loop through all fields and unlink if they are not a Field
Formula? If so, then the loop has to be on the outside and the test for
..wdFieldType within the loop.
 
S

singeredel

Yes, I believe you are right. It is the second choice. The final version of
the code ended up being as follows, which seems to work:

With Documents(CurrentDocument) [previously defined in code]
Dim af As Field
For Each af In .Fields
If af.Type <> wdFieldExpression Then
af.Unlink
End If
Next af
End With

Thanks for your reply!
 

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