Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

locating spaces in filenames

Status
Not open for further replies.

harky

Technical User
Oct 29, 2001
39
0
0
GB
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top