我試圖使用下面的代碼刪除html標籤,但它什麼也沒做。我試過再次運行它,但沒有用。有人可以請告知可能是什麼問題。使用html標籤附加文件的快照。有關信息,數據來自MS Access和MS Access鏈接到Sharepoint列表。使用正則表達式,但它不會刪除excel表中的html標籤
Sub Import_AccessData()
Dim strtKeyMsgRange As Range
Dim KeyMsgRange As Range
Dim KeyMsgRangeCell As Range
Dim endKeyMsgRangeCell As Range
Set strtKeyMsgRange = Range("B2")
Set endKeyMsgRange = Range("AC13")
Set KeyMsgRange = Range(strtKeyMsgRange, endKeyMsgRange)
For Each KeyMsgRangeCell In KeyMsgRange
a = StripHTML(KeyMsgRangeCell)
KeyMsgRangeCell.Value = a
Next KeyMsgRangeCell
End Sub
Public Function StripHTML(cell As Range) As String
Dim RegEx As Object
Set RegEx = CreateObject("vbscript.regexp")
Dim sInput As String
Dim sOut As String
sInput = cell.Value
With RegEx
.Global = True
.IgnoreCase = True
.MultiLine = True
.Pattern = "<[^>]+>" 'Regular Expression for HTML Tags.
.Pattern = " "
.Pattern = "&"
End With
sOut = RegEx.Replace(sInput, "")
StripHTML = sOut
Set RegEx = Nothing
End Function
正則表達式操縱HTML只會讀到瘋狂。 –
我認爲[Jeff Atwood](http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html)說得最好。 – psubsee2003
我不想用正則表達式。我手頭有一個問題(即來自Sharepoint導入數據的html標籤),我會採用任何方法來擺脫這些標籤。有什麼建議嗎? – joiner