Word VBA: Convert text boxes to plain text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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