Set objDictionary = CreateObject(“Scripting.Dictionary”)
Set objWord = CreateObject(“Word.Application”)
objWord.Visible = True
Set objDoc = objWord.Documents.Open(“C:\Scripts\Sample.doc”)
Set colWords = objDoc.Words
For Each strWord in colWords
strWord = LCase(strWord)
strLetter = Left(strWord, 1)
If ASC(strLetter) < 97 OR ASC(strLetter) > 122 Then
Else
If objDictionary.Exists(strWord) Then
Else
objDictionary.Add strWord, StrWord
End If
End If
Next
Set objDoc2 = objWord.Documents.Add()
Set objSelection = objWord.Selection
For Each strItem in objDictionary.Items
objSelection.TypeText strItem & vbCrLf
Next
Set objRange = objDoc2.Range
objRange.Sort
您需要的是 Microsoft Word 文档中所有单词的完整索引,这可以通过宏来完成,例如devblogs.Microsoft.com和Answers.Microsoft.com中的这些。请注意,某些字符,例如句点(结束符)被计为单词。
下面引用了来自 devblogs 的代码。