用于添加HTML标签的Excel VBA

我有以下代码来添加单元格的文本。 但它不附加HTML标签。

例如:

9/23/99 10:37 am我们不去。 我在残疾。 哥伦布不是繁荣的地方。 这大部分是退役军人。 她打电话问为什么她是唯一的一个。 也想要她的伴侣。 我解释说在会议中发生。 9/10/99 4:15p Rick Ludwig转介$ 995想要Essex Funding&Associates Inc. WY 4262-3607-0011-9582 8/01 8/23/99 9:08 am想要一个NV公司。 需要做一些周围的金融变革。 几个程序。 MU和导师。 我和我的伙计…我60岁了。

它应该是像

“HTML段落标记”9/23/99 10:37 am我们不走了。 我在残疾。 哥伦布不是繁荣的地方。 这大部分是退役军人。 她打电话问为什么她是唯一的一个。 也想要她的伴侣。 我解释说在会议中发生。 “HTML段落标记结束”“HTML段落标记”9/10/99无需担心

以下是我得到的代码

Option Explicit Sub main() Dim newStrng As String Dim word As Variant Dim strngToBeAppended As String strngToBeAppended = Application.InputBox("Input string to be appended", 1) With Worksheets("TextSheet") '<-- change "TextSheet" to your actual sheet with text name For Each word In Split(.Range("A1").Text, " ") '<-- assuming that the text to be splitted is in cell "A1" of the referenced worksheet If Len(word) - Len(Replace(word, "/", "")) = 2 Then newStrng = newStrng & " " & strngToBeAppended & word Else newStrng = newStrng & " " & word End If Next word .Range("A2").Value = LTrim(newStrng) End With End Sub 

尝试这个:

 Option Explicit Sub main() Dim newStrng As String Dim word As Variant Dim parTag As String, endParTag As String Dim dateCounter As Long parTag = "<p>" '<-- change this to whatever your "HTML Paragraph Tag" may be endParTag = "</p>" '<-- change this to whatever your "End of HTML Paragraph Tag" may be With Worksheets("TextSheet") '<-- change "TextSheet" to your actual sheet with text name For Each word In Split(.Range("A1").Text, " ") '<-- assuming that the text to be splitted is in cell "A1" of the referenced worksheet If Len(word) - Len(Replace(word, "/", "")) = 2 Then dateCounter = dateCounter + 1 If dateCounter > 1 Then newStrng = newStrng & endParTag newStrng = newStrng & parTag & word Else newStrng = newStrng & " " & word End If Next word If dateCounter > 1 Then newStrng = newStrng & endParTag .Range("A2").Value = LTrim(newStrng) End With End Sub