![]() |
|
|
|
#1
|
|||
|
|||
|
Does anybody know of a macro that will highlight a specific number of words based on a numeric input in MS Word?
For instance, I would like to enter a number in a dialog box, such as 250, and have 250 words hightlighted in a document that I can then copy or delete. I know I can manually highlight words to get a count, but I sometimes have to highlight an odd number such as 537 words, and I always either go too far or not far enough and it gets frustrating. Thanks. |
|
#2
|
||||
|
||||
|
hi icsjohn,
Try the following macro. It counts from the start of the selected range and doesn't care whether the current selection is more, or less, than the desired word count. Code:
Sub Demo()
Dim i As Long
i = InputBox("How many words do you want to select?", "Word Marker")
With Selection
While .Range.ComputeStatistics(Statistic:=wdStatisticWords) < i
.MoveEnd wdWord, i - .Range.ComputeStatistics(Statistic:=wdStatisticWords)
Wend
End With
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
This worked perfectly. Thank you very much.
|
|
| Tags |
| highlight, macro, word count |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Mail Merge to create specific number of table rows
|
flackend | Mail Merge | 4 | 12-01-2023 02:49 PM |
Page number Macro
|
kimsi | Word | 3 | 11-15-2011 11:54 PM |
How to get the number of words in the file (please see details)?
|
Jamal NUMAN | Word | 24 | 07-24-2011 04:39 PM |
Need help extracting specific text from one doument to another with macro/VBA.
|
zsmithku | Word | 1 | 04-15-2011 03:46 PM |
| Why Words doesn’t show the style of the selected words automatically???? | Jamal NUMAN | Word | 0 | 04-14-2011 03:20 PM |