Hi
I need to run a macro across a batch of files to determine if there are illegal characters in there - at the moment it works fine, except for picking up spaces in filenames. The code so far is:
Dim NameCheck As New RegExp
Dim i As Integer
Dim ch As String
Dim illegalCharacters As New Collection
Dim v As Variant
Dim ic As String
On Error GoTo trap:
NameCheck.pattern = "([a-zA-Z0-9_]|-|\s|\u00A0|\u0020|\u0096|\u0097|\.|,|&|')"
For i = 1 To Len(ActiveDocument.name)
ch = Mid(ActiveDocument.name, i, 1)
If NameCheck.Test(ch) = False Then
illegalCharacters.add ch
End If
Next i
If illegalCharacters.count > 0 Then
FncValidateFilename = True
fName = ActiveDocument.name
For Each v In illegalCharacters
ic = v & ic & " "
Next v
Call addMessage("FncValidateFilename", ActiveDocument, "Invalid filename. Illegal characters: " & ic)
Exit Function
End If
FncValidateFilename = True
Exit Function
trap:
FncValidateFilename = False
End Function
any ideas? I put the unicode of u0020 into the exceptions list but it still isn't being picked up
I need to run a macro across a batch of files to determine if there are illegal characters in there - at the moment it works fine, except for picking up spaces in filenames. The code so far is:
Dim NameCheck As New RegExp
Dim i As Integer
Dim ch As String
Dim illegalCharacters As New Collection
Dim v As Variant
Dim ic As String
On Error GoTo trap:
NameCheck.pattern = "([a-zA-Z0-9_]|-|\s|\u00A0|\u0020|\u0096|\u0097|\.|,|&|')"
For i = 1 To Len(ActiveDocument.name)
ch = Mid(ActiveDocument.name, i, 1)
If NameCheck.Test(ch) = False Then
illegalCharacters.add ch
End If
Next i
If illegalCharacters.count > 0 Then
FncValidateFilename = True
fName = ActiveDocument.name
For Each v In illegalCharacters
ic = v & ic & " "
Next v
Call addMessage("FncValidateFilename", ActiveDocument, "Invalid filename. Illegal characters: " & ic)
Exit Function
End If
FncValidateFilename = True
Exit Function
trap:
FncValidateFilename = False
End Function
any ideas? I put the unicode of u0020 into the exceptions list but it still isn't being picked up