DELETE MULTIPLE TEXT BOXES

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a document of approx 240 pages with manually inserted headers on every
page in a text box. I need to delete all of them and replace with a proper
header. How can I do this quickly? I have reduced the view to 50% and held
the Ctrl key down as I select each text box and then delete but I can only do
eight at a time and it is killing my wrist as I click to select each one in
the small view. I have tried search and replace but it can't find the text
box. PLEASE HELP ME SOMEONE. It will take me hours!
 
Courtesy of Stefan Blom, Word MVP:
You can use the following macro to delete all text boxes and their
contents:

Sub DeleteAllTextBoxes()
Dim s As Shape
For Each s In ActiveDocument.Shapes
If s.Type = msoTextBox Then
s.Delete
End If
Next s
End Sub

If you need assistance, see
http://www.gmayor.com/installing_macro.htm.
 
Unfortunately code that work work seemingly perfect in the main text
area of a document will fail miserably in the other storyranges.
Insert a few textboxes in a header or footer and you will see for
yourself.

In this case the OP want textboxes in the headers to be deleted.
There are three types of headers in each section of a document. So:

Sub DeleteHeaderTextBoxes()
Dim oShapes As Shapes
Dim i As Long
Dim j As Long
Dim k As Long
For i = 1 To ActiveDocument.Sections.Count
For j = 1 To 3
Set oShapes = ActiveDocument.Sections(i).Headers(j).Shapes
For k = oShapes.Count To 1 Step -1
If oShapes(k).Type = msoTextBox Then
oShapes(k).Delete
End If
Next k
Next j
Next i
Set oShapes = Nothing
End Sub
 
Yay, Aeneas! Thank you so much. It worked! That has saved me so much time
and so much pain. Your blood is worth bottling. All I did was copy and
paste it into Macro under Tools in Word and ran the macro. Easy. Thanks,
again. Lyn
 
Aeneas,

My apologies for challenging your posted solution. On reading the OP a
little closer I see that the troublesome text boxes were in fact in
documents maintext story and the code you posted will work.
 
No need to apologize. I've already copied your code to handle text boxes in
headers. Thanks so much for all your tips through the years!
 
You're welcome but thanks should go to Stefan Blom, who wrote the code. I
sensed you were in a tight bind and needed help fast.
 

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

Back
Top