How to delete all the equations in a document?

D

Danny

To delete all shapes/tables, I used
For Each obj In ActiveDocument.Shapes
obj.Delete
Next

For Each tbl In ActiveDocument.Tables
tbl.Delete
Next

Is there something similar to delete all the equations?
 
G

Graham Mayor

You could use

With ActiveDocument
For i = .Fields.Count To 1 Step -1
If .Fields(i).Type = wdFieldEmbed Then
If InStr(1, .Fields(i), "Equation.3") Then
.Fields(i).Delete
End If
End If
Next i
End With

or

For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldEmbed Then
If InStr(1, oField, "Equation.3") Then
oField.Delete
End If
End If
Next oField


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

Danny

It doesn't work.
When I display the Fields.Count in a msgbox, I get the result "0".
With <Alt>+F9, I don't see codes either!
I'm sure that the equation is in the document, I can see it in a box when I
click on it.
 
S

Stefan Blom

I believe Graham's code only works with the Microsoft Equation 3 objects of
Word 97-2003. Are you perhaps using Word 2007 and the new equation feature
available in that version?
 
D

Danny

Yes, I'm using Word2007!

Stefan Blom said:
I believe Graham's code only works with the Microsoft Equation 3 objects of
Word 97-2003. Are you perhaps using Word 2007 and the new equation feature
available in that version?
 
S

Stefan Blom

I suspect that you cannot access Word 2007 equations via VBA (but I could be
wrong).
 
J

Jay Freedman

Stefan, you may be pleased to know that you can access (and manipulate!) the
new equations, using the OMaths collection and a lot of new machinery
associated with it.

Danny, here's the code you want:

Sub DeleteAllEqs()
Dim eq As OMath
For Each eq In ActiveDocument.OMaths
eq.Range.Delete
Next
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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