How to develop an Excel Macro that contains regular expressions so it will work in Windows and Mac

痞子三分冷 提交于 2019-11-28 09:56:26

Unfortunately no solution for this has yet been found — the current workaround is to simply replace regular expressions with a series of Replace calls (or other required operation).

I hit this problem trying to use the regexp library when trying to strip html tags from a cell.

I know this wasn't noted within the question as the desired use but, in case it is or future visitors are trying to replace a regex function to remove HTML from tags within a cell within Mac Excel 2011, this user defined function will work. Apologies to the original author, i found it only but can no longer find the source i'm afraid.

Public Function StripHTML(zDataIn As String) As String

  Dim iStart As Integer
  Dim iEnd   As Integer
  Dim iLen   As Integer

  Do While InStr(zDataIn, "<") > 0
    iStart = InStr(zDataIn, "<")
    iEnd = InStr(iStart, zDataIn, ">")
    iLen = Len(zDataIn)
    If iStart = 1 Then
      zDataIn = Right(zDataIn, iLen - iEnd)
    Else
      If iLen = iEnd Then
        zDataIn = Left(zDataIn, iStart - 1)
      Else
        zDataIn = Mid(zDataIn, 1, iStart - 1) & _
                  Right(zDataIn, iLen - iEnd)
      End If
    End If
  Loop

  StripHTML = zDataIn

End Function

If you don't mind paying US$99, there is Aivosto RegExpr. Apparently this is a pure VBA solution, that should run on both PC and Mac VBA.

Alternatively, write separate solutions for both PC and Mac, then use compiler directives to separate which bit of code runs on each platform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!