none
Word 2016 VBA 显示的句子和词汇数量(内容)明显不正确 RRS feed

  • 问题

  • 大家好:

    我有用下面的VBA:

    Sub ListAllSentencesAndWords()

    With ActiveDocument

    Debug.Print "Total No. of sentences: " & .Sentences.Count

    For Each snt In .Sentences

    n = n + 1

    Debug.Print "Sentence #" & Str(n); ":" & snt.text

    Debug.Print vbTab & "Total No. of words: " & snt.Words.Count

    For Each wrd In snt.Words

    m = m + 1

    Debug.Print vbTab & vbTab & "Word #" & Str(m); ":" & wrd.text

    Next

    Next

    End With

    End Sub

    对下面的Word文档内容进行测试:

    I am counting 0.

    I am counting 1. I am counting 2. I am counting 3.

    联合国 1993年,纽约

    得到下面的结果:

    Total No. of sentences: 3

    Sentence # 1:I am counting 0.


        Total No. of words: 6

            Word # 1:I 

            Word # 2:am 

            Word # 3:counting 

            Word # 4:0

            Word # 5:.

            Word # 6:


    Sentence # 2:I am counting 3.


        Total No. of words: 6

            Word # 7:I 

            Word # 8:am 

            Word # 9:counting 

            Word # 10:3

            Word # 11:.

            Word # 12:


    Sentence # 3:联合国 1993年,纽约


        Total No. of words: 7

            Word # 13:联合国

            Word # 14:联合国 

            Word # 15:1993

            Word # 16:1993年

            Word # 17:,

            Word # 18:纽约

            Word # 19:


    很明显,Word丢掉了两句话(即第二段前两句),并且所统计的词汇有重复(在最后一句中)。这是怎么回事?

    JW


    A translator by profession, a desktop publisher by trade, a coder by interest

    2018年12月20日 3:27

全部回复