Group: microsoft.public.word.vba.general
From: "Greg Maxey"
Date: Saturday, March 08, 2008 8:21 AM
Subject: Re: Word frequency count

Klaus,

Nice job!

I don't understand this part:
> ' Or, if you want to define what characters can appear in words
> explicitly ' (and ignore the rest):
> ' Case "a" To "z", "@", "~", _
> ' "$", "%", "§", "&", "A" To "Z", _
> ' "0" To "9", "'", "-", "_"

Can you post (or send me e-mail) showing exactly how the code would look
using this option and an example. Thanks.


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org
~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Klaus Linke wrote:
> Playing with the scripting dictionary recently, I've written such a
> macro...
> You need to check the "MIcrosoft Scripting Runtime" in "Tools >
> References".
> Regards,
> Klaus
>
> Dim sText As String
> sText = ActiveDocument.Content.Text
> Dim dicWords As New Scripting.Dictionary
> Dim vPlaces(0)
> Dim vItem As Variant
> Dim i As Long
> Dim sWord As String, sChar As String
> sWord = ""
> For i = 1 To Len(sText)
> sChar = MID(sText, i, 1)
> Select Case sChar
> ' delimiters:
> Case ChrW(9), ChrW(10), ChrW(13), ChrW(32), ChrW(34), ".", ",", _
> "<", ">", "/", ";", _
> "(", ")", "[", "]", _
> ":", "#", "+", "*", _
> "?", "!"
> If Len(sWord) <> 0 Then
> If dicWords.Exists(key:=sWord) Then
> vItem = dicWords(key:=sWord)
> ReDim Preserve vItem(UBound(vItem) + 1)
> vItem(UBound(vItem)) = i
> dicWords(key:=sWord) = vItem
> Else
> vPlaces(0) = i
> dicWords.Add sWord, vPlaces
> End If
> sWord = ""
> End If
> Case Else
> ' Or, if you want to define what characters can appear in words
> explicitly ' (and ignore the rest):
> ' Case "a" To "z", "@", "~", _
> ' "$", "%", "§", "&", "A" To "Z", _
> ' "0" To "9", "'", "-", "_"
> sWord = sWord & sChar
> End Select
> Next i
> Dim vWord As Variant
> For Each vWord In dicWords.Keys
> Debug.Print vWord, UBound(dicWords.Item(key:=vWord)) + 1
> Next vWord