Her er lidt til dem der har fulgt... eller i fremtiden søger...
Lav et Word dokument - skriv =rannd(8,4) og tryk enter (for at få lidt demo tekst)
Skriv noget i sidehoved også... og leg lidt med denne makro
God fornøjelse
Public Sub WordsInfo()
Dim oStory As Object
Dim lWordCount As Long, lMainCount As Long, lHeaderCount As Long
'Loop through each story range and only include the footer and Main story to the word count
For Each oStory In ActiveDocument.StoryRanges
'Vi kunne lave en select case på hver story type, hvis deres individuelle word count var vigtig - se types her
'
https://docs.microsoft.com/en-us/office/vba/api/word.wdstorytype Select Case oStory.StoryType
Case wdMainTextStory
lMainCount = oStory.ComputeStatistics(wdStatisticWords)
lWordCount = lWordCount + oStory.ComputeStatistics(wdStatisticWords)
Case wdPrimaryHeaderStory, wdFirstPageHeaderStory, wdEvenPagesHeaderStory
lHeaderCount = lHeaderCount + oStory.ComputeStatistics(wdStatisticWords)
lWordCount = lWordCount + oStory.ComputeStatistics(wdStatisticWords)
Case Else
lWordCount = lWordCount + oStory.ComputeStatistics(wdStatisticWords)
End Select
Next oStory
Debug.Print "Antal ord i Headers er: " & lHeaderCount
Debug.Print "Antal ord i Mainstory er: " & lMainCount
Debug.Print "Antal ord story by story er: " & lWordCount
With ActiveDocument.Range
Debug.Print .ComputeStatistics(wdStatisticWords)
Debug.Print .ComputeStatistics(wdStatisticCharacters)
Debug.Print .ComputeStatistics(wdStatisticCharactersWithSpaces)
Debug.Print .ComputeStatistics(wdStatisticFarEastCharacters)
Debug.Print .ComputeStatistics(wdStatisticLines)
Debug.Print .ComputeStatistics(wdStatisticPages)
Debug.Print .ComputeStatistics(wdStatisticParagraphs)
'Svar på dette spørgsmål kunne være - men den tæller 0 linier med... og giver en skæv statistik
Debug.Print "Antal ord pr. linie: " & .ComputeStatistics(wdStatisticWords) / .ComputeStatistics(wdStatisticLines)
End With
'Det mere korrekte svar på dette spørgsmål er
Dim lLines As Long, x As Long, lCountLines As Long
lLines = ActiveDocument.Range.ComputeStatistics(wdStatisticLines)
Selection.HomeKey wdStory
For x = 1 To lLines
With Selection
.EndKey Unit:=wdLine, Extend:=wdExtend
If .Characters.Count > 1 Then lCountLines = lCountLines + 1
.Collapse wdCollapseStart
.MoveDown Unit:=wdLine, Count:=1
End With
Next x
Debug.Print "Antal ord pr. linie: " & ActiveDocument.Range.ComputeStatistics(wdStatisticWords) / lCountLines
End Sub