So I have a database I am constantly pulling data from into an Excel sheet. One of the columns is RTF notes which when pulled display in the excel cell with 'gibberish' around the body of text. If I double click on the cell as if to edit it and press enter Excel automatically updates the cell and displays the body without the 'gibberish'. Is there a way to automate this process either a formula, a text setting or VBA code that could automate entering the cell to register that and auto convert the field?
Additional info I can add from solutions I've tried so far. I am using Office 365 and am using a 64 bit pc
Example of the data:
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}{\f1\fswiss\fprq2\fcharset0 System;}}
\viewkind4\uc1\pard\f0\fs20 This is an example of test information
\par
\par Here is more text\b\f1
\par }
CodePudding user response:
I have a 64bit system and a slight rework of the first answer in stackoverflow.com/questions/1673025 works for me:
Sub ConvertRTFcell()
Dim rngCell As Range
Dim wdDoc As Word.Document
Dim ff As Integer
fn = "C:\temp\File_ParseRTF.rtf"
For Each rngCell In Range("P10:P15")
If Trim(rngCell.Value) Like "{*}" Then
ff = FreeFile
Open fn For Output As #ff
Print #ff, rngCell.Value
Close #ff
Set wdDoc = GetObject(fn)
rngCell.Value = wdDoc.Range.Text
wdDoc.Close False
Kill fn
Set wdDoc = Nothing
End If
Next
End Sub
You'll need Word installed, and a reference in Excel project to Microsoft Word xx.0 Object Library'