Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-07-2011, 07:48 AM
icsjohn icsjohn is offline Macro for highlighting specific number of words Windows XP Macro for highlighting specific number of words Office 2003
Novice
Macro for highlighting specific number of words
 
Join Date: Dec 2011
Posts: 2
icsjohn is on a distinguished road
Post Macro for highlighting specific number of words

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.
Reply With Quote
  #2  
Old 12-07-2011, 04:39 PM
macropod's Avatar
macropod macropod is offline Macro for highlighting specific number of words Windows 7 64bit Macro for highlighting specific number of words Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 12-07-2011, 06:44 PM
icsjohn icsjohn is offline Macro for highlighting specific number of words Windows XP Macro for highlighting specific number of words Office 2003
Novice
Macro for highlighting specific number of words
 
Join Date: Dec 2011
Posts: 2
icsjohn is on a distinguished road
Default

This worked perfectly. Thank you very much.
Reply With Quote
Reply

Tags
highlight, macro, word count



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro for highlighting specific number of words Mail Merge to create specific number of table rows flackend Mail Merge 4 12-01-2023 02:49 PM
Macro for highlighting specific number of words Page number Macro kimsi Word 3 11-15-2011 11:54 PM
Macro for highlighting specific number of words How to get the number of words in the file (please see details)? Jamal NUMAN Word 24 07-24-2011 04:39 PM
Macro for highlighting specific number of words 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

Other Forums: Access Forums

All times are GMT -7. The time now is 10:44 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft