Excel转换(引号)"到" e;没有搞砸html链接

时间:2015-08-28 22:30:47

标签: html excel excel-vba vba

我有一个excel文件,从我们的网站导出带引号"需要用html实体替换:

"

此:

Dimensions are 7" wide by 5" tall.

需要看起来像:

Dimensions are 7" wide by 5" tall

一个简单的excel find和replace就可以了,但是我们还有合法的引号需要保留,因为它们嵌入在这样的html链接中:

<a href="http://www.daylightcolor.com/csl/index.php?c=11" target="_blank">

如何在不触及a href标签内的任何引号的情况下找到并替换常规引号?

1 个答案:

答案 0 :(得分:2)

使用"(?![^<]*>)正则表达式尝试此方法,它将替换>后面没有的双引号:

Sub CallReplMultiple()
Dim ptrn As String, txt As String
Dim regExp As Object

ptrn = """(?![^<]*>)"
Set regExp = CreateObject("VBScript.RegExp")
With regExp
    .Global = True
    .Pattern = ptrn
End With

For i = 1 To ActiveSheet.UsedRange.Rows.Count
  For j = 1 To ActiveSheet.UsedRange.Columns.Count
    ActiveSheet.Cells(i, j) = regExp.Replace(ActiveSheet.Cells(i, j).Value, "&quot;")
  Next j
Next i

End Sub