A family of Microsoft word processing software products for creating web, email, and print documents.
Somewhat more robust:
Sub JustTheFirstShape()
With ActiveDocument.Shapes
If .Count <> 0 Then .Item(1).Delete
End With
End Sub
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have a text box at the beginning of my word docs that instructs the user to do a few things. When they are done, I would like a macro to delete the text box. I used the following, and it works great IF THERE IS ONLY ONE TEXT BOX IN MY DOCUMENT. Unfortunately (of course) sometimes there is more than one text box. How can I modify this to have it delete the FIRST text box only?
Sub SelectAllShapes()
ActiveDocument.Shapes.SelectAll
End Sub
Please keep in mind I am a vba beginner at best...
A family of Microsoft word processing software products for creating web, email, and print documents.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Answer accepted by question author
Somewhat more robust:
Sub JustTheFirstShape()
With ActiveDocument.Shapes
If .Count <> 0 Then .Item(1).Delete
End With
End Sub
Answer accepted by question author
I don't do Word programming unless forced, but try this on for size...
Sub JustTheFirstShape()
ActiveDocument.Shapes(1).Delete
End Sub
The code should delete the the first shape added to the document.
(not necessarily the shape at the top of the document)
'---
Jim Cone
Portland, Oregon USA
https://goo.gl/IUQUN2 (Dropbox)
(free & commercial excel add-ins & workbooks)
To delete the shape that appears first in the document, rather than the one that was first inserted, if it is not the one that appears first in the document, use:
With ActiveDocument
If .Shapes.Count <> 0 Then
.range.ShapeRange.Item(1).Delete
End If
End With