简体   繁体   English

如何使用VBA遍历MS Word 2010文档中的单词列表?

[英]How to iterate over the list of words in a MS Word 2010 document with VBA?

What I'm actually trying to do is implementing a button to compute the Gunning fog index . 我实际上想做的是实现一个按钮来计算Gunning雾指数 What I would normally do in anything other than VBA is: 除了VBA,我通常会做的是:

  1. Provide a dictionary of words considered to be "complex" (to be compiled from professional jargon that should be used only when necessary) 提供被认为是“复杂”的单词词典(由专业术语汇编而成,仅在必要时使用)
  2. Get the list of words in the document. 获取文档中的单词列表。
  3. Determine the length of this list. 确定此列表的长度。
  4. Get the number of sentences (possibly just the number of "dot whitespace" occurrences) and determine the average words/sentence 获取句子的数量(可能只是“点空白”出现的数量)并确定平均单词/句子
  5. Filter the list of words the "complex" words and compare the length of the "complex word list" with the length of the "word list". 过滤“复杂”单词的单词列表,并将“复杂单词列表”的长度与“单词列表”的长度进行比较。

What I don't know how to do is how to get an object "this documents.wordList", and what are the "length", and "filter is-complex" methods would be. 我不知道该怎么做是如何获取对象“ this document.wordList”,“ length”和“ filter is-complex”方法分别是什么。

This doesn't need to be specially elegant, it's for personal use only. 不需要特别优雅,仅用于个人用途。

The .Find method, combined with a counter that adds 1 to itself each time a word is found, could provide a list of complex words in the document. .Find方法与一个计数器相结合,该计数器每次发现一个单词时对其自身加1,可以提供文档中复杂单词的列表。 The length would simply be the counter at the end of the search. 该长度只是搜索结束时的计数器。

The Words.Count property will return the number of all words in the document. Words.Count属性将返回文档中所有单词的数量。 Similarly you could do Sentences.Count for the number of sentences. 同样,您可以执行Sentences.Count来计算句子数。

This should get you pointed in the right direction. 这应该使您指向正确的方向。 Visit the Word VBA help files for more info on this and other possibilities. 请访问Word VBA帮助文件 ,以获取有关此功能和其他可能性的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM