2012-03-15 6 views
0

私はコードサンプルが入った大きな文書を持っています。サイズにかかわらず、フォントCalibri(本文)のすべてのテキストの語数を知りたいです。私はConsolas等を無視したい。Microsoft Word文書の単語をフォントで数えますか?

イタリック(例として掲示されていますが、実行することができません。

Sub IgnoreItalics() 
    Dim lngWord As Long, lngCountIt As Long 

    lngCountIt = 0 

    For lngWord = 1 To ActiveDocument.Words.Count 
     If ActiveDocument.Words(lngWord).Italic Then 
      lngCountIt = lngCountIt + 1 
     End If 
    Next lngWord 

    MsgBox "Number of non-italic words: " & _ 
    ActiveDocument.BuiltInDocumentProperties("Number of words") - 
    lngCountIt 
End Sub 

これをConsolasに変更する方法はありますか?レコードの

+0

これについては何が実行されませんか?あなたはエラー、無効な結果などを取得していますか? – Gaffi

+0

私はそれが文書だったかもしれないと思う、それは私の環境の下でそれがコードだったかもしれないと思ったので、最後に31kの言葉です。 –

+0

興味深い。あなたのコードでは、 'ActiveDocument.Words.Count'と' ActiveDocument.BuiltInDocumentProperties( "単語数") 'の両方を使用します。あなたは両方のポジションでちょうどオンまたはもう片方を使って試しましたか? – Gaffi

答えて

2

はあなたのコードを変更する、ここに私のため

Sub CountTypeface() 
    Dim lngWord As Long 
    Dim lngCountIt As Long 
    Const Typeface As String = "Calibri" 

    For lngWord = 1 To ActiveDocument.Words.Count 
     'Ignore any document "Words" that aren't real words (CR, LF etc) 
     If Len(Trim(ActiveDocument.Words(lngWord))) > 1 Then 
      If ActiveDocument.Words(lngWord).Font.Name = Typeface Then 
       lngCountIt = lngCountIt + 1 
      End If 
     End If 
    Next lngWord 

    MsgBox "Number of " & Typeface & " words: " & lngCountIt 
End Sub 
の作品ソリューションです
+0

これは私のためにうまくいった –

1

は、あなたのコードを変更するだけで少しが私の仕事:あなたがうまくいけば、それを理解することができるように

Sub CountFonts() 

Dim lngWord As Long, lngCountIt As Long 
lngCountIt = 0 
For lngWord = 1 To ActiveDocument.Words.Count 
If ActiveDocument.Words(lngWord).Font.Name = "Calibri" Then 
lngCountIt = lngCountIt + 1 
End If 
Next lngWord 

MsgBox "Number of non-Calibri words: " & _ 
ActiveDocument.BuiltInDocumentProperties("Number of words") - lngCountIt 
End Sub 
+0

動作しているように見えますが、コードが終了すると正しくマークされます。言葉では応答していませんが、それは大きな文書ですので、うまくいけば、その時間はちょうどtaknigです。 –

-1

使用

ActiveDocument.ComputeStatistics(wdStatisticWords) 

または

ActiveDocument.ComputeStatistics(0) 
関連する問題