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 - [\/:*?<>|]
I'm using RegExp like so:
Dim regEx As New RegExp
Dim strSpecChar As String: strSpecChar = "*[\/:*?<>|]*" '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
I'm getting Compile Error: Invalid Character
error because of the bar (|
) character. I've tried escaping bar with backslash but it doesn't work. Can someone help? I've read a couple posts including this one but it hasn't helped.
SOLUTION: Take a look at blog.tkacprow.pl
's comment below and Alex
's answer (he helped point out a typo and explains error 5018. Remove *
from the strSpecChar variable above.