SubscribeSub CountNonEnglishCharacters()
Set BadChars = New Collection
BadChars.Add Item:=""""
BadChars.Add Item:="("
BadChars.Add Item:=")"
BadChars.Add Item:="1"
BadChars.Add Item:="2"
BadChars.Add Item:="3"
BadChars.Add Item:="4"
BadChars.Add Item:="5"
BadChars.Add Item:="6"
BadChars.Add Item:="7"
BadChars.Add Item:="8"
BadChars.Add Item:="9"
BadChars.Add Item:="0"
BadChars.Add Item:="%"
BadChars.Add Item:="^#"
BadChars.Add Item:="^w"
BadChars.Add Item:="^$"
BadChars.Add Item:="&"
BadChars.Add Item:=","
BadChars.Add Item:="/"
BadChars.Add Item:="-"
BadChars.Add Item:="."
BadChars.Add Item:="'"
BadChars.Add Item:=":"
BadChars.Add Item:="。"
BadChars.Add Item:=","
BadChars.Add Item:="("
BadChars.Add Item:=")"
BadChars.Add Item:=" "
BadChars.Add Item:="【"
BadChars.Add Item:="】"
BadChars.Add Item:="["
BadChars.Add Item:="]"
BadChars.Add Item:="《"
BadChars.Add Item:="》"
CurrentFile = Dir("DIRECTORY PATH*.doc")
TotalCount = 0
While CurrentFile <> ""
' MsgBox ("c:\temp\Marbridge\" & CurrentFile)
Documents.Open FileName:="DIRECTORY PATH" & CurrentFile, ReadOnly:=True
For Each candidate In BadChars
With Selection.Find
.Text = candidate
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next candidate
ThisCount = ActiveDocument.Characters.Count
TotalCount = TotalCount + ThisCount
ActiveDocument.Close savechanges:=False
CurrentFile = Dir
Wend
MsgBox ("There is a total of " & TotalCount & " characters.")
End Sub>
You are not logged in, either login or create an account to post comments
A quick approximation would be to count every character outside of the Ascii range, but that could overcount some things.
posted by delmoi at 9:31 PM on March 30