Question

I want to get the formatted text of an excel cell as RTF using VBA (to store the formatted text in a database). If it's not possible to get the text as RTF, how could I store the formatted text in a database and keep the formatting?

Thanks!

Was it helpful?

Solution

If you also have Word then you can use Automation. The following code copy the cell into a new Word application and save it as rtf file.

Sub SaveRTF()
   Dim objWD As Word.Application
   Dim wdDoc As Word.Document

   Set objWD = CreateObject("Word.Application")
   objWD.Documents.Add
   Set wdDoc = objWD.ActiveDocument
   wdDoc.Select
   ThisWorkbook.Worksheets("Sheet1").Cells(1, 1).Copy 'Change cell reference and sheet name
   objWD.Selection.Paste
   wdDoc.SaveAs2 "C:\\Users\\YourName\\Documents\\FormatFile.rtf", wdFormatRTF 'Change File Name here
   wdDoc.Close

   Set wdDoc = Nothing
   Set objWD = Nothing
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top