Skip to content

Instantly share code, notes, and snippets.

@monoxgas
Forked from githubyouser/EraseTextBoxes.bas
Last active March 14, 2023 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monoxgas/ee0c4a5f501253b595603773eafbc5b7 to your computer and use it in GitHub Desktop.
Save monoxgas/ee0c4a5f501253b595603773eafbc5b7 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 ReplaceTextBoxes()
Dim RngDoc As Range, RngShp As Range, i As Long, boundary As String
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
If RngShp.Font.Name = "Consolas" Or RngShp.Font.Name = "Courier New" Then
boundary = "```"
Else
boundary = "@@@"
End If
RngShp.InsertParagraphBefore
RngShp.InsertBefore boundary
RngShp.InsertParagraphAfter
RngShp.InsertAfter boundary
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