title: VBA RegExp for Special Characters
body: <p>When a user enters a "save as" name for the output from my Macros, I want to check for special characters that will cause an error in saving a file - <code>[\/:*?&lt;&gt;|]</code></p>
  
  <p>I'm using RegExp like so:</p>
  
  <pre><code>Dim regEx As New RegExp
  Dim strSpecChar As String: strSpecChar = "*[\/:*?&lt;&gt;|]*" 'Compile Error here
  Dim OutputFileName As String: OutputFileName = InputBox("Enter File Name")
  With regEx
      .Global = True
      .MultiLine = True
      .IgnoreCase = True
      .Pattern = strSpecChar
  End With
  If regEx.Test(OutputFileName) Then
          'error msg
  End If
  </code></pre>
  
  <p>I'm getting <code>Compile Error: Invalid Character</code> error because of the bar (<code>|</code>) character. I've tried escaping bar with backslash but it doesn't work. Can someone help? I've read a couple posts including <a href="https://stackoverflow.com/questions/22542834/how-to-use-regular-expressions-regex-in-microsoft-excel-both-in-cell-and-loops">this one</a> but it hasn't helped.</p>
  
  <p><strong>SOLUTION:</strong> Take a look at <code>blog.tkacprow.pl</code>'s comment below and <code>Alex</code>'s answer (he helped point out a typo and explains error 5018. Remove <code>*</code> from the strSpecChar variable above.</p>