Skip to content

Instantly share code, notes, and snippets.

@githubyouser
Created February 6, 2023 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save githubyouser/28e8f56ac59697abeee4a05d88afd94d to your computer and use it in GitHub Desktop.
Save githubyouser/28e8f56ac59697abeee4a05d88afd94d to your computer and use it in GitHub Desktop.
Word VBA: Convert text boxes to plain text
'https://answers.microsoft.com/en-us/msoffice/forum/all/removing-text-box-from-word-document-without/a4d02b2f-d168-48dc-960b-4a45cbe79d86
Sub EraseTextBoxes()
Dim RngDoc As Range, RngShp As Range, i As Long
With ActiveDocument
For i = .Shapes.Count To 1 Step -1
With .Shapes(i)
'If .Type = msoTextBox Then
'https://eileenslounge.com/viewtopic.php?p=28255#p28255
If .TextFrame.HasText = True Then
Set RngShp = .TextFrame.TextRange
RngShp.InsertParagraphBefore
RngShp.InsertBefore "@@@@@"
RngShp.InsertParagraphAfter
RngShp.InsertAfter "@@@@@"
RngShp.InsertParagraphAfter
RngShp.End = RngShp.End - 1
Set RngDoc = .Anchor
RngDoc.Collapse wdCollapseEnd
RngDoc.FormattedText = RngShp.FormattedText
.Delete
End If
End With
Next
End With
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment