Ok... im getting there i think, on further inspection i have narrowed it down
to the
lngIndex = 1 To 8
loop in there it doesn't seem to be stopping as soon as the range = "" and
seems to go right up to Com9 and then trying to print whatever is in there
(Nothing at all). So can any1 see the error in this as i am stumped.
With ActiveDocument
For lngIndex = 1 To 8
If .Bookmarks(BOOKMARK_LABEL & CStr(lngIndex)).Range = "" Then
If lngIndex = 1 Then
MsgBox "There are not valid bookmarked ranges in this document.
"
Else
lngIndex = lngIndex - 1
Exit For
End If
End If
Next lngIndex
strBookmark = .Bookmarks(BOOKMARK_LABEL & CStr(lngIndex)).Range
Call WriteProp(sPropName:="Comments", sValue:=strBookmark)
End With
Hi VinceB1,
1. VBA is generous in what it allows, but this can lead to all kinds of weird
errors that are difficult to track down. Technically, if you use "Range" what
you get back is a Range. VBA allows for "default properties" which means if you
try to assign "Range" to something else it will see if the default property
(.Text) fits. To assign the contents of a bookmark to a string variable you
should *technically* use: str = .Bookmarks(index).Range.Text
2. If you're unsure how many bookmarks the document may contain, then I would
suggest
Dim lBookmarks as Long
lBookmarks = ActiveDocument.Bookmarks.Count
for i = 1 to lBookmarks
3. In order to avoid errors, test whether a bookmark exists before trying to
address it:
If .Bookmark.Exists(BOOKMARK_LABEL & CStr(lngIndex)) Then
4. Then, as Jezebel mentioned, it's more efficient to test the Length of a
string, rather than whether it's "empty". I think this test, on a RANGE object,
may be where things are going wrong for you. Test
If Len(.Bookmarks(BOOKMARK_LABEL & CStr(lngIndex)).Range.TEXT) = 0
> Ok... im getting there i think, on further inspection i have narrowed it down
> to the
[quoted text clipped - 25 lines]
> Call WriteProp(sPropName:="Comments", sValue:=strBookmark)
> End With
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)