What I want to do
I have an Access database ( C:\Users\289894\Desktop\Database1.accdb ) One of the fields of [Table1] is [Memo].
That field is of the Memo
data type, with the text format set to rich text
.
It makes it possible to save some records as Bold and some records saved as Italics, for example.
I want to open a connexion to this Access database from an excel file in order to read/write into this rich text field.
The code I used is the following:
Dim datab As Database
Dim rs As Recordset
Dim path As String
path = "C:\Users\289894\Desktop\Database1.accdb"
Set datab = OpenDatabase(path)
Set rs = datab.OpenRecordset("SELECT * FROM [Table1]")
Debug.Print rs!Memo
Range("A1") = rs!Memo
My question
This code works well to open a connexion and read ordinary text fields, but rich text acts in a surprising way (for me). The original text in access was "aaa". That's "aaa" in bold font.
After running the code, both the debug.print and Range("A1") have <div><strong>aaa</strong></div>
written into them.
How can I change my code to send the format to excel as well? I'd like to have "aaa" written in bold in cell A1, just like it is in Access.
EDIT: Workaround This solves the immediate problem asked by the question without really answering the question itself. It uses internet explorer to paste the text back as Rich Text, without the tags.
Sub Sample()
Dim Ie As Object
Dim rng As Range
Set rng = Feuil1.Range("A1")
Set Ie = CreateObject("InternetExplorer.Application")
With Ie
.Visible = False
.Navigate "about:blank"
.Document.body.InnerHTML = rng.Value
.ExecWB 17, 0
'Select all contents in browser
.ExecWB 12, 2
'Copy them
ActiveSheet.Paste Destination:=rng
.Quit
End With
End Sub
html
tags and make the cells bold, or italic, depending on the tag. Also the title seems to have nothing to do with the question. – Scott Holtzman