![]() |
|
|||||||
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Hi...
I want to be able to place a number after every 100 words in a document. 100 after the first 100 words, 200 after the first 200 words, etc. Everything I've tried (with Copilot's help) inserts a number every 75-85 words, evidently including non-word characters. Any wisdom you can offer either about achieving an accurate word count, or about achieving my overall aim, would be appreciated. Here's the latest version, which was supposed to address the undercount by identifying only actually, but didn't. TIA! Code:
Sub InsertNumbersEveryHundredWords()
Dim doc As Document
Dim wordCount As Long
Dim i As Long
Dim counter As Long
Dim rng As Range
Set doc = ActiveDocument
wordCount = 0
counter = 100
For i = 1 To doc.Words.Count
If wordCount >= 30000 Then Exit For
' Check if the current item is a word
If Trim(doc.Words(i)) <> "" And Not doc.Words(i).Text Like "[!A-Za-z0-9]" Then
wordCount = wordCount + 1
End If
If wordCount Mod 100 = 0 Then
Set rng = doc.Words(i).Duplicate
rng.Collapse Direction:=wdCollapseEnd
rng.Text = " " & counter
counter = counter + 100
End If
Next i
End Sub
Last edited by macropod; 06-29-2025 at 05:15 PM. Reason: Added code tags for code formatting |
| Tags |
| wordcount |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Macro to insert certain words if the number of words than 20
|
laith93 | Word VBA | 6 | 10-28-2022 01:12 AM |
Select and change font size of words by number of characters
|
knpaddac | Word VBA | 3 | 03-15-2021 03:00 PM |
Forumla to find all words over three characters
|
14spar15 | Excel | 8 | 10-02-2020 09:58 AM |
How show characters instead words (status bar)
|
BrunoChirelli | Word | 2 | 02-19-2015 12:03 PM |
Color words ending with special characters
|
Singh_Edm | Word | 2 | 01-20-2014 12:51 AM |