在VBA的Access中将RTF嵌入式OLE转换为HTML
我有一个表,它有一个内嵌的OLE字段,其中包含RichText格式的数据。我需要将这些数据传输到MySQL数据库并将其转换为HTML。我使用访问权限。有没有一种方法可以在VBA中快速完成?在VBA的Access中将RTF嵌入式OLE转换为HTML,html,vba,ms-access,rtf,converters,Html,Vba,Ms Access,Rtf,Converters,我有一个表,它有一个内嵌的OLE字段,其中包含RichText格式的数据。我需要将这些数据传输到MySQL数据库并将其转换为HTML。我使用访问权限。有没有一种方法可以在VBA中快速完成? 我在网上搜索过,大多数人使用RichText控件(richtx32.ocx)来获取纯文本,但我需要它保持格式,我也没有这个控件 以下是我解决问题的方法: Option Explicit Public wrd As Word.Application Public doc As Word.Document Fu
我在网上搜索过,大多数人使用RichText控件(richtx32.ocx)来获取纯文本,但我需要它保持格式,我也没有这个控件 以下是我解决问题的方法:
Option Explicit
Public wrd As Word.Application
Public doc As Word.Document
Function RTF2HTMLviaWord(rtf As String) As String
'Open Tools --> References --> and check Microsoft Scripting Runtime
Dim fso As New FileSystemObject
Dim text As TextStream
Dim temp As String
temp = Environ("TEMP")
If Len(rtf) > 1 Then
Set text = fso.CreateTextFile(temp & "\RTF2HTML.rtf", True)
text.Write rtf
text.Close
If wrd Is Nothing Then
Set wrd = New Word.Application
End If
Set doc = wrd.Documents.Open(temp & "\RTF2HTML.rtf", False)
doc.SaveAs temp & "\RTF2HTML.htm", wdFormatHTML
doc.Close
fso.DeleteFile temp & "\RTF2HTML.rtf"
Set text = fso.OpenTextFile(temp & "\RTF2HTML.htm", ForReading, False)
RTF2HTMLviaWord = text.ReadAll
text.Close
fso.DeleteFile temp & "\RTF2HTML.htm"
Else
RTF2HTMLviaWord = ""
End If
End Function
唯一的缺点是Word会产生太多垃圾HTML标记。我希望它可以保存最少的HTML标记,而无需格式化。您是否尝试过RichText=True的常规文本框?它将数据保存为HTML(HTML的一小部分)。