Linda si chiede se c’è un modo per contare il numero di parole che si trovano nei commenti (e solo i commenti) in un documento.

Il modo più semplice per eseguire questa operazione è utilizzare una macro. Questo perché Word rende disponibile a VBA una raccolta di commenti che include tutti i commenti nel documento. Tutto quello che devi fare è scorrere ogni commento e poi guardare la proprietà Count per la raccolta Words per il commento, in questo modo:

Sub CommentWordCount1()

Dim c As Comment     Dim lWords As Long     Dim sMsg As String

For Each c In ActiveDocument.Comments         lWords = lWords + c.Range.Words.Count     Next c

sMsg = "There are " & ActiveDocument.Comments.Count     sMsg = sMsg & " comments in the document. & vbCrLf & vbCrLf     sMsg = sMsg & "Word count: " & lWords     MsgBox sMsg End Sub

Se preferisci, potresti anche usare il metodo ComputeStatistics per inventare il conteggio delle parole, in questo modo:

Sub CommentWordCount2()

Dim c As Comment     Dim lWords As Long     Dim sMsg As String

For Each c In ActiveDocument.Comments         lWords = lWords + c.Range.ComputeStatistics(wdStatisticWords)

Next c

sMsg = "There are " & ActiveDocument.Comments.Count     sMsg = sMsg & " comments in the document. & vbCrLf & vbCrLf     sMsg = sMsg & "Word count: " & lWords     MsgBox sMsg End Sub

Quando confronti i risultati delle due macro, potresti notare una differenza nel conteggio delle parole. Ciò è dovuto al modo in cui il metodo CompuStatistics tratta la punteggiatura durante i calcoli.

Ti consigliamo di confrontare i risultati e, in base alle caratteristiche delle informazioni nei tuoi commenti, scegliere l’approccio più adatto alle tue esigenze.

_Nota: _

Se desideri sapere come utilizzare le macro descritte in questa pagina (o in qualsiasi altra pagina dei siti WordTips), ho preparato una pagina speciale che include informazioni utili.

WordTips è la tua fonte di formazione economica su Microsoft Word.

(Microsoft Word è il software di elaborazione testi più popolare al mondo.) Questo suggerimento (13531) si applica a Microsoft Word 2007, 2010, 2013 e 2016.