How to remove all captions 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 captions?
Delete captions from shapes/tables WITHOUT deleting the shapes/tables, ONLY
the captions.
 
G

Graham Mayor

Captions are sequence fields so to remove SEQ fields, the following macro
will do
that

Dim sLabel As String
sLabel = "Label"
With ActiveDocument
For i = .Fields.Count To 1 Step -1
If .Fields(i).Type = wdFieldSequence Then
' If InStr(1, .Fields(i), sLabel) Then
.Fields(i).Delete
'End If
End If
Next i
End With

It is possible to have several numbering sequences in a document. If you
only want to remove the SEQ fields for a particular sequence, then remove
the initial quotes from the quoted lines and set the sequence name in the
variable sLabel

You will also have to remove the leading and traliing text eg the following
will remove all Equation captions

Dim sLabel As String
Dim oRng As Range
sLabel = "Equation"
With ActiveDocument
For i = .Fields.Count To 1 Step -1
If .Fields(i).Type = wdFieldSequence Then
If InStr(1, .Fields(i), sLabel) Then
.Fields(i).Select
Set oRng = Selection.Range.Paragraphs(1).Range
oRng.Delete
End If
End If
Next i
End With


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - 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