W
ward
Hello,
I would like to be able to *easily* retrieve the text from
a numbered list paragraph (title), which is also a
bookmark.
E.g. from the following line
2.3.1 Dummy title
I would like to retrieve "Dummy title". The bookmark would
contain [Dummy title].
This seems rather simple by using something like:
Dim bm As Bookmark
For Each bm In ActiveDocument.Bookmarks
Debug.Print bm.Name, bm.Range.Text
Next
However, the paragraph might contain a manual page break
(because a user has entered one), which causes the
bookmark to start just before this manual page break.
This, of course, will make the bm.range.text property also
return the page break (which i don't want). In the debug
screen it's visualised as a little square, but when the
string is pasted somewhere in word, it does contain the
pagebreak.
Does anybody knows how to *easily* get just the text?
Ward
Ps: I've found a workaround to get what i want (see
below), but it's way to complicated. I figure it should be
possible to do it more simple.
'Check if the paragraph is preceded by a 'manual page break
'because this should be removed from the range
If Left(Rng.Paragraphs(1).Range, 1) = Chr$(12) Then
If mDoDebug Then Debug.Print "Pagebreak before"
Rng.SetRange Start:=Rng.Start + 1, End:=Rng.End
End If
'Do not include 'enter' at the end of the line
Rng.SetRange Start:=Rng.Start, End:=Rng.End - 1
'save range for later handling
Set mTargetParRange = Rng
'Return header/paragraph text
RtrnParagraphText = Trim(Rng.Text)
I would like to be able to *easily* retrieve the text from
a numbered list paragraph (title), which is also a
bookmark.
E.g. from the following line
2.3.1 Dummy title
I would like to retrieve "Dummy title". The bookmark would
contain [Dummy title].
This seems rather simple by using something like:
Dim bm As Bookmark
For Each bm In ActiveDocument.Bookmarks
Debug.Print bm.Name, bm.Range.Text
Next
However, the paragraph might contain a manual page break
(because a user has entered one), which causes the
bookmark to start just before this manual page break.
This, of course, will make the bm.range.text property also
return the page break (which i don't want). In the debug
screen it's visualised as a little square, but when the
string is pasted somewhere in word, it does contain the
pagebreak.
Does anybody knows how to *easily* get just the text?
Ward
Ps: I've found a workaround to get what i want (see
below), but it's way to complicated. I figure it should be
possible to do it more simple.
'Check if the paragraph is preceded by a 'manual page break
'because this should be removed from the range
If Left(Rng.Paragraphs(1).Range, 1) = Chr$(12) Then
If mDoDebug Then Debug.Print "Pagebreak before"
Rng.SetRange Start:=Rng.Start + 1, End:=Rng.End
End If
'Do not include 'enter' at the end of the line
Rng.SetRange Start:=Rng.Start, End:=Rng.End - 1
'save range for later handling
Set mTargetParRange = Rng
'Return header/paragraph text
RtrnParagraphText = Trim(Rng.Text)