0

以下のコードを使用して html タグを削除しようとしていますが、何もしません。もう一度実行してみましたが、役に立ちません。誰かが問題の原因を教えてください。html タグを使用してファイルのスナップショットを添付します。情報については、データは MS Access から取得され、MS Access は SharePoint リストにリンクしています。

ここに画像の説明を入力

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 = "&nbsp;"
   .Pattern = "&amp;"
 End With

 sOut = RegEx.Replace(sInput, "")
 StripHTML = sOut
 Set RegEx = Nothing
End Function
4

1 に答える 1

1

Pattern プロパティを複数回設定しています。最後に割り当てられた値のみが保持されます ( &amp;)。

実際にこれを行うには、3 つの正規表現 ( "<[^>]+>" => """&nbsp;" => " ""&amp;" => "&")、またはすべての入力に一致する 1 つの表現( )を使用する必要があります。"(&amp;)|(&nbsp;)|(<[^>]+>)" => ""

于 2012-10-10T19:47:06.927 に答える