[英]Excel VBA For Adding HTML Tag
我有以下代碼用於附加單元格的文本。 但是它沒有附加HTML標記。
例如:
9/23/99 10:37 am我們不去。 我正在殘廢。 哥倫布不是繁榮的地方。 大部分是退休軍人。 她打電話問她為什么是唯一的一個。 也要她的伴侶。 我在會議上解釋了這種情況。 99年9月10日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段落標記” 99/9/23/10:37我們不去。 我正在殘廢。 哥倫布不是繁榮的地方。 大部分是退休軍人。 她打電話問她為什么是唯一的一個。 也要她的伴侶。 我在會議上解釋了這種情況。 “ HTML段落標記的結尾”“ HTML段落標記” 99/9/10無需擔心
以下是我得到的代碼
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.