singeredel said:
I cannot seem to find how to write VBA code to delete a DocVariable
field in the ActiveDocument. I have a DocVariable field with the name
of "Quadis" that I want to delete if a certain "If statement" is
false.
Thanks...
I see at least two points of confusion here. Please clarify what you're
asking for...
- Do you want to delete the {DocVariable} field from the body of the
document, or do you want to delete the document variable itself (which would
cause the field to display nothing when it's updated, although the field is
still there)?
- If it's the field you want to delete, then fields don't have names. Do you
mean that the name of the document variable is "Quadis" and the field code
is {DocVariable Quadis} ?
To delete a document variable, set its value to an empty string:
ActiveDocument.Variables("Quadis").Value = ""
To delete all DocVariable fields that refer to this variable, loop through
all fields and test their codes:
Dim oFld As Field
For Each oFld In ActiveDocument.Fields
If (oFld.Type = wdFieldDocVariable) And _
(InStr(oFld.Code, "Quadis") > 0) Then
oFld.Delete
End If
Next oFld