문서를 분석 할 때 단어 빈도 목록을 만드는 방법이 있는지 궁금 할 수 있습니다. 즉, 나타나는 횟수와 함께 문서의 모든 고유 단어 목록을 생성 할 수 있습니다.

불행히도 Word에는 이러한 기능이 포함되어 있지 않습니다. 그러나 매크로를 사용하여 직접 만들 수 있습니다. 다음 VBA 매크로는 예입니다.

Sub WordFrequency()

Dim SingleWord As String           'Raw word pulled from doc     Const maxwords = 9000              'Maximum unique words allowed     Dim Words(maxwords) As String      'Array to hold unique words     Dim Freq(maxwords) As Integer      'Frequency counter for unique words     Dim WordNum As Integer             'Number of unique words     Dim ByFreq As Boolean              'Flag for sorting order     Dim ttlwds As Long                 'Total words in the document     Dim Excludes As String             'Words to be excluded     Dim Found As Boolean               'Temporary flag     Dim j As Integer                   'Temporary variables     Dim k As Integer                   '     Dim l As Integer                   '     Dim Temp As Integer                '     Dim tword As String                '

' Set up excluded words     Excludes = "[the][a][of][is][to][for][this][that][by][be][and][are]"



' Find out how to sort     ByFreq = True     ans = InputBox$("Sort by WORD or by FREQ?", "Sort order", "WORD")

If ans = "" Then End     If UCase(ans) = "WORD" Then         ByFreq = False     End If          Selection.HomeKey Unit:=wdStory     System.Cursor = wdCursorWait     WordNum = 0     ttlwds = ActiveDocument.Words.Count

' Control the repeat     For Each aword In ActiveDocument.Words         SingleWord = Trim(LCase(aword))

If SingleWord < "a" Or SingleWord > "z" Then SingleWord = ""    'Out of range?

If InStr(Excludes, "[" & SingleWord & "]") Then SingleWord = "" 'On exclude list?

If Len(SingleWord) > 0 Then             Found = False             For j = 1 To WordNum                 If Words(j) = SingleWord Then                     Freq(j) = Freq(j) + 1                     Found = True                     Exit For                 End If             Next j             If Not Found Then                 WordNum = WordNum + 1                 Words(WordNum) = SingleWord                 Freq(WordNum) = 1             End If             If WordNum > maxwords - 1 Then                 j = MsgBox("The maximum array size has been exceeded. _                   Increase maxwords.", vbOKOnly)

Exit For             End If         End If         ttlwds = ttlwds - 1         StatusBar = "Remaining: " & ttlwds & "     Unique: " & WordNum     Next aword

' Now sort it into word order     For j = 1 To WordNum - 1         k = j         For l = j + 1 To WordNum             If (Not ByFreq And Words(l) < Words(k)) Or                 (ByFreq And Freq(l) > Freq(k)) Then k = l         Next l         If k <> j Then             tword = Words(j)

Words(j) = Words(k)

Words(k) = tword             Temp = Freq(j)

Freq(j) = Freq(k)

Freq(k) = Temp         End If         StatusBar = "Sorting: " & WordNum - j     Next j

' Now write out the results     tmpName = ActiveDocument.AttachedTemplate.FullName     Documents.Add Template:=tmpName, NewTemplate:=False     Selection.ParagraphFormat.TabStops.ClearAll     With Selection         For j = 1 To WordNum             .TypeText Text:=Trim(Str(Freq(j))) & vbTab & Words(j) & vbCrLf         Next j     End With     System.Cursor = wdCursorNormal     j = MsgBox("There were " & Trim(Str(WordNum)) & _         " different words ", vbOKOnly, "Finished")

End Sub

문서를 열고이 매크로를 실행하면 단어 또는 빈도로 정렬 된 목록을 만들 것인지 묻는 메시지가 나타납니다. 단어를 선택하면 결과 목록이 알파벳 순서로 표시됩니다. 빈도를 선택하면 단어가 문서에 나타난 횟수를 기준으로 결과 목록이 내림차순으로 표시됩니다.

매크로가 실행되는 동안 상태 표시 줄은 무슨 일이 일어나고 있는지 나타냅니다.

문서의 크기와 컴퓨터 속도에 따라 매크로를 완료하는 데 시간이 걸릴 수 있습니다. (349,000 개 이상의 단어가 포함 된 719 페이지의 문서로 실행했으며 완료하는 데 약 5 분이 걸렸습니다.)

Excludes 문자열에 값을 설정하는 줄이 매크로에 있습니다. 이 문자열에는 단어 목록을 모을 때 매크로가 무시할 단어가 포함됩니다. 목록에 단어를 추가하려면 [대괄호] 사이의 문자열에 추가하면됩니다. 또한 제외 단어가 소문자인지 확인하십시오.

_ 참고 : _

이 페이지 (또는 WordTips 사이트의 다른 페이지)에 설명 된 매크로를 사용하는 방법을 알고 싶다면 유용한 정보가 포함 된 특별 페이지를 준비했습니다.

link : / wordribbon-WordTipsMacros [새 브라우저 탭에서 특별 페이지를 열려면 여기를 클릭하세요].

_WordTips_는 비용 효율적인 Microsoft Word 교육을위한 소스입니다.

(Microsoft Word는 세계에서 가장 널리 사용되는 워드 프로세싱 소프트웨어입니다.)이 팁 (879)은 Microsoft Word 97, 2000, 2002 및 2003에 적용됩니다.