Skip to content

Instantly share code, notes, and snippets.

Forked from githubyouser/EraseTextBoxes.bas
Last active March 14, 2023 16:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Word VBA: Convert text boxes to plain text
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
If .TextFrame.HasText = True Then
Set RngShp = .TextFrame.TextRange
If RngShp.Font.Name = "Consolas" Or RngShp.Font.Name = "Courier New" Then
boundary = "```"
boundary = "@@@"
End If
RngShp.InsertBefore boundary
RngShp.InsertAfter boundary
RngShp.End = RngShp.End - 1
Set RngDoc = .Anchor
RngDoc.Collapse wdCollapseEnd
RngDoc.FormattedText = RngShp.FormattedText
End If
End With
End With
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment