Convert RTF (Rich Text Format) code into plain text in Excel

后端 未结 2 951
暗喜
暗喜 2020-12-11 11:38

I exporting a database query as Excel and I am getting rows with RTF formatting.

How can I convert these fields into plain text? I\'ve found answers that

2条回答
  •  离开以前
    2020-12-11 12:02

    Another alternative can be using Microsoft Rich Textbox Control (but can't test it on x64 Office)

    Sub rtfToText()
        With CreateObject("RICHTEXT.RichtextCtrl") ' or add reference to Microsoft Rich Textbox Control for early binding and With New RichTextLib.RichTextBox
            .SelStart = 0                          ' needs to be selected
            .TextRTF = Join(Application.Transpose(Cells.CurrentRegion.Columns(1)))
            [C1] = .Text                           ' set the destination cell here
    
            ' or if you want them in separate cells:
            a = Split(.Text, vbNewLine)
            Range("C3").Resize(UBound(a) + 1) = Application.Transpose(a)
        End With
    End Sub
    

提交回复
热议问题