Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 466761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:30:46+00:00 2026-05-12T23:30:46+00:00

I have approx. 12000 cells in excel containing RTF (including formatting tags). I need

  • 0

I have approx. 12000 cells in excel containing RTF (including formatting tags). I need to parse them to get to the unformatted text.

This is the example of one of the cells with text:

{\rtf1\ansi\deflang1060\ftnbj\uc1
{\fonttbl{\f0 \froman \fcharset0 Times New Roman;}{\f1 \fswiss \fcharset238
Arial;}}
{\colortbl ;\red255\green255\blue255 ;\red0\green0\blue0 ;}
{\stylesheet{\fs24\cf2\cb1 Normal;}{\cs1\cf2\cb1 Default Paragraph Font;}}
\paperw11908\paperh16833\margl1800\margr1800\margt1440\margb1440\headery720\footery720
\deftab720\formshade\aendnotes\aftnnrlc\pgbrdrhead\pgbrdrfoot
\sectd\pgwsxn11908\pghsxn16833\marglsxn1800\margrsxn1800\margtsxn1440\margbsxn1440
\headery720\footery720\sbkpage\pgncont\pgndec
\plain\plain\f1\fs24\pard TPR 0160 000\par IPR 0160 000\par OB-R-02-28\par}

And all I really need is this:

TPR 0160 000
IPR 0160 000
OB-R-02-28

The problem with simple looping over the cells and removing unnecessary formatting is, that not everything in those 12000 cells is as straightforward as this is. So I would need to manually inspect many different versions and write several variations; and still at the end there would be a lot of manual work to do.

But if I copy the contents of one cell to empty text document and save it as RTF, then open it with MS Word, it instantly parses the text and I get exactly what I want. Unfortunately it’s extremely inconvenient to do so for a 12000 cells.

So I was thinking about VBA macro, to move cell contents to Word, force parsing and then copy the result back to the originating cell. Unfortunately I’m not really sure how to do it.

Does anybody has any idea? Or a different approach? I will be really grateful for a solution or a push in the right direction.

TNX!

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T23:30:46+00:00Added an answer on May 12, 2026 at 11:30 pm

    If you did want to go down the route of using Word to parse the text, this function should help you out. As the comments suggest, you’ll need a reference to the MS Word Object Library.

    Function ParseRTF(strRTF As String) As String
    Dim wdDoc As Word.Document 'Ref: Microsoft Word 11.0 Object Library'
    Dim f     As Integer       'Variable to store the file I/O number'
    
    'File path for a temporary .rtf file'
    Const strFileTemp = "C:\TempFile_ParseRTF.rtf"
    
    'Obtain the next valid file I/O number'
    f = FreeFile
    
    'Open the temp file and save the RTF string in it'
    Open strFileTemp For Output As #f
        Print #f, strRTF
    Close #f
    
    'Open the .rtf file as a Word.Document'
    Set wdDoc = GetObject(strFileTemp)
    
    'Read the now parsed text from the Word.Document'
    ParseRTF = wdDoc.Range.Text
    
    'Delete the temporary .rtf file'
    Kill strFileTemp
    
    'Close the Word connection'
    wdDoc.Close False
    Set wdDoc = Nothing
    End Function
    

    You could call it for each of your 12,000 cells using something similar to this:

    Sub ParseAllRange()
    Dim rngCell As Range
    Dim strRTF  As String
    
    For Each rngCell In Range("A1:A12000")
    
        'Parse the cell contents'
        strRTF = ParseRTF(CStr(rngCell))
    
        'Output to the cell one column over'
        rngCell.Offset(0, 1) = strRTF
    Next
    End Sub
    

    The ParseRTF function takes about a second to run (on my machine at least), so for 12,000 cells this will work out at about three and a half hours.


    Having thought about this problem over the weekend, I was sure there was a better (quicker) solution for this.

    I remembered the RTF capabilities of the clipboard, and realised that a class could be created that would copy RTF data to the clipboard, paste to a word doc, and output the resulting plain text. The benefit of this solution is that the word doc object would not have to be opened and closed for each rtf string; it could be opened before the loop and closed after.

    Below is the code to achieve this. It is a Class module named clsRTFParser.

    Private Declare Function GlobalAlloc Lib "kernel32" _
                    (ByVal wFlags&, ByVal dwBytes As Long) As Long
    Private Declare Function GlobalLock Lib "kernel32" _
                    (ByVal hMem As Long) As Long
    Private Declare Function GlobalUnlock Lib "kernel32" _
                    (ByVal hMem As Long) As Long
    Private Declare Function lstrcpy Lib "kernel32" _
                    (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
    
    Private Declare Function OpenClipboard Lib "user32" _
                    (ByVal Hwnd As Long) As Long
    Private Declare Function EmptyClipboard Lib "user32" () As Long
    Private Declare Function RegisterClipboardFormat Lib "user32" Alias _
                    "RegisterClipboardFormatA" (ByVal lpString As String) As Long
    Private Declare Function SetClipboardData Lib "user32" _
                    (ByVal wFormat As Long, ByVal hMem As Long) As Long
    Private Declare Function CloseClipboard Lib "user32" () As Long
    
    '---'
    
    Dim wdDoc As Word.Document 'Ref: Microsoft Word 11.0 Object Library'
    
    Private Sub Class_Initialize()
    Set wdDoc = New Word.Document
    End Sub
    
    Private Sub Class_Terminate()
    wdDoc.Close False
    Set wdDoc = Nothing
    End Sub
    
    '---'
    
    Private Function CopyRTF(strCopyString As String) As Boolean
    Dim hGlobalMemory  As Long
    Dim lpGlobalMemory As Long
    Dim hClipMemory    As Long
    Dim lngFormatRTF   As Long
    
    'Allocate and copy string to memory'
    hGlobalMemory = GlobalAlloc(&H42, Len(strCopyString) + 1)
    lpGlobalMemory = GlobalLock(hGlobalMemory)
    lpGlobalMemory = lstrcpy(lpGlobalMemory, strCopyString)
    
    'Unlock the memory and then copy to the clipboard'
    If GlobalUnlock(hGlobalMemory) = 0 Then
        If OpenClipboard(0&) <> 0 Then
            Call EmptyClipboard
    
            'Save the data as Rich Text Format'
            lngFormatRTF = RegisterClipboardFormat("Rich Text Format")
            hClipMemory = SetClipboardData(lngFormatRTF, hGlobalMemory)
    
            CopyRTF = CBool(CloseClipboard)
        End If
    End If
    End Function
    
    '---'
    
    Private Function PasteRTF() As String
    Dim strOutput As String
    
    'Paste the clipboard data to the wdDoc and read the plain text result'
    wdDoc.Range.Paste
    strOutput = wdDoc.Range.Text
    
    'Get rid of the new lines at the beginning and end of the document'
    strOutput = Left(strOutput, Len(strOutput) - 2)
    strOutput = Right(strOutput, Len(strOutput) - 2)
    
    PasteRTF = strOutput
    End Function
    
    '---'
    
    Public Function ParseRTF(strRTF As String) As String
    If CopyRTF(strRTF) Then
        ParseRTF = PasteRTF
    Else
        ParseRTF = "Error in copying to clipboard"
    End If
    End Function
    

    You could call it for each of your 12,000 cells using something similar to this:

    Sub CopyParseAllRange()
    Dim rngCell As Range
    Dim strRTF  As String
    
    'Create new instance of clsRTFParser'
    Dim RTFParser As clsRTFParser
    Set RTFParser = New clsRTFParser
    
    For Each rngCell In Range("A1:A12000")
    
        'Parse the cell contents'
        strRTF = RTFParser.ParseRTF(CStr(rngCell))
    
        'Output to the cell one column over'
        rngCell.Offset(0, 1) = strRTF
    Next
    End Sub
    

    I have simulated this using example RTF strings on my machine. For 12,000 cells it took two and a half minutes, a much more reasonable time frame!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a need to manage a large number (approx 20+) languages for our
I have a folder with approx 10000 images, and I need to copy about
I have a library consisting of approx 100 source files. I want one of
Have you managed to get Aptana Studio debugging to work? I tried following this,
I have a website that has approx 1000 different strings in a mysql database
I have a large SVG file (approx. 60 MB, 10000x10000 pixels but with the
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have just started using Visual Studio Professional's built-in unit testing features, which as I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.