Reputation: 365
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!
Upvotes: 4
Views: 4535
Reputation: 493
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
Upvotes: 4