Skip to content

Instantly share code, notes, and snippets.

@rabarbara
Created July 12, 2017 13:13
Show Gist options
  • Save rabarbara/303e724e96f6220dc4ef54324f03d821 to your computer and use it in GitHub Desktop.
Save rabarbara/303e724e96f6220dc4ef54324f03d821 to your computer and use it in GitHub Desktop.
Removing All Text Boxes In a Document
' Source: https://wordribbon.tips.net/T009169_Removing_All_Text_Boxes_In_a_Document.html
Sub RemoveTextBox2()
Dim shp As Shape
Dim oRngAnchor As Range
Dim sString As String
For Each shp In ActiveDocument.Shapes
If shp.Type = msoTextBox Then
' copy text to string, without last paragraph mark
sString = Left(shp.TextFrame.TextRange.Text, _
shp.TextFrame.TextRange.Characters.Count - 1)
If Len(sString) > 0 Then
' set the range to insert the text
Set oRngAnchor = shp.Anchor.Paragraphs(1).Range
' insert the textbox text before the range object
oRngAnchor.InsertBefore _
"Textbox start << " & sString & " >> Textbox end"
End If
shp.delete
End If
Next shp
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment