empty paragraph marks as "blank lines" is a really bad idea. It messes up
the use of styles, the "keep with next" paragraph property, and any number
of other things. Instead, you should be designing your styles to use the
Space Before and Space After settings to provide visual space with _no_
empty paragraph marks. It's only when you're dealing with files that are
meant for other purposes (such as text files that will be stored in a
database) that two paragraph marks together become unavoidably necessary.
You don't really need to count the number of blank lines, you just need to
know when there are more than one. Further, one blank line is created by two
consecutive paragraph marks (represented by the VBA constant vbCr).
This macro starts by assigning a Range object (myRg) to hold the range of
the bookmark (which I supposed to have the name "bk1"). I collapse myRg to
the beginning of the bookmark, and then extend the start of myRg backward
until the preceding character is no longer a paragraph mark. That leaves the
range covering all the consecutive paragraph marks that immediately precede
the bookmark. If the length of that range is more than two characters, I set
the text of the range to two paragraph marks.
Dim myRg As Range
If ActiveDocument.Bookmarks.Exists("bk1") Then
Set myRg = ActiveDocument.Bookmarks("bk1").Range
.MoveStartWhile cset:=vbCr, Count:=wdBackward
If .Characters.Count > 2 Then
.Text = vbCr & vbCr
Unfortunately this simple code will alter the bookmark. If you need the
bookmark to stay put for later processing, post back.
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.