View Single Post
 
Old 10-28-2022, 01:01 AM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,166
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

There are different ways to calculate a word count in Word. The way the earlier code determines word count is not what a normal English speaker would consider the Word count - it includes punctuation as a word. This code modification uses an alternate method to arrive at a word count and might work better for your documents
Code:
Sub Macro1()
  Dim iWords As Double, sFiller As String, arrFiller() As String, i As Integer
  sFiller = "I didn't bother to attempt my homework by myself but I asked someone on the internet to do it for me"
  arrFiller = Split(sFiller, " ")
  iWords = ActiveDocument.Range.ComputeStatistics(wdStatisticWords)   'ActiveDocument.Words.Count
  If iWords < 20 Then
    For i = 0 To 19 - iWords
      ActiveDocument.Range.InsertAfter " " & arrFiller(i)
    Next i
  End If
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote