title: Escape string for Regex in Excel
body: <p>I am trying to find keywords in an Excel cell.</p>
  
  <pre><code>Function findString(pattern As String, haystack As String)
  
      Dim RegEx As Object
      Dim strTest As String
      Dim valid As Boolean
      Dim Matches As Object
  
      Dim found As Boolean
  
      Set RegEx = CreateObject("VBScript.RegExp")
  
      ' Initialise Regex object
      With RegEx
          '.Global = False
          .IgnoreCase = True
          .MultiLine = True
      End With
  
      ' I need something like this here:        
      'RegEx.pattern = RegEx.Escape(pattern)
      RegEx.pattern = pattern
  
      'return value
      findString = RegEx.test(haystack)
  
      Set RegEx = Nothing
  
  End Function
  </code></pre>
  
  <p>pattern is the keyword.
  However, this keyword can contain special characters. Example: D|Sign
  This should be escaped to "D\|Sign" before regex is executed.</p>
  
  <p>How can I escape this string so that only cells containing the input string are found?</p>