Thread: [Solved] Loop Until End of Document
View Single Post
 
Old 02-20-2021, 02:02 PM
macropod's Avatar
macropod macropod is offline Windows 10 Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Quote:
Originally Posted by Stephen Ray View Post
Here is a Macro that loops until the end of the document.
...
If that highlighted Paragraph Mark is also the last Paragraph Mark in the document, BINGO!
What does that achieve the you don't get with:
Code:
Sub ParagraphCount()
MsgBox ActiveDocument.Paragraphs.Count
End Sub
or:
Code:
Sub ParagraphCount()
MsgBox ActiveDocument.ComputeStatistics(wdStatisticParagraphs)
End Sub
without:
• all the flickering;
• messing with the selected range;
• the overhead of a loop; and
• having to insert a quite arbitrary exit point to overcome your code's propensity for locking up Word?

Furthermore, your code doesn't handle tables correctly.

Moreover, since you haven't defined what 'counter' is, that:
• can result in complier errors (i.e. if one uses 'Option Explicit', which is always good practice); and
• results in an variant, which is less efficient to use than if it was properly defined it as a long.

PS: When posting code, please use the code tags, indicated by the # button on the posting menu. Without them, your code loses much of whatever structure it had.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote