word bookmarks 
Author Message
 word bookmarks

--
Bob Lohse

Does anyone know how to find the Next bookmark in the document without
explicitly specifying its' name using VBA in a macro?  In other words, if I
am at insertion point A and beyond it there is a book mark, I want to move
the insertion point to the bookmark and read what the bookmark is.  If there
are no more bookmarks, it should return a false.



Sun, 23 May 2004 06:50:22 GMT  
 word bookmarks
Hi Bob,

Try this

Selection.GoToNext What:=wdGoToBookmark

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
Word FAQs at http://www.multilinker.com/wordfaq
Please post any follow-up in the newsgroup. I do not reply to Word questions
by email


Quote:

> --
> Bob Lohse

> Does anyone know how to find the Next bookmark in the document without
> explicitly specifying its' name using VBA in a macro?  In other words, if
I
> am at insertion point A and beyond it there is a book mark, I want to move
> the insertion point to the bookmark and read what the bookmark is.  If
there
> are no more bookmarks, it should return a false.



Sun, 23 May 2004 08:27:22 GMT  
 word bookmarks
Hi Jonathon,

I was playing with the following macro when I ran across this message. I
tried

Selection.GoToNext What:=wdGoToBookmark

as well as the abbreviated form:

Selection.GoToNext wdGoToBookmark

Both returned errors in a document where there were bookmarks both before
and after the selection point. The error message is:
Runtime Error 4120: Bad parameter

The code I was playing with is for a macro to report the name(s) of any
bookmark(s) at the cursor:

Sub GetSelectedBookmarkName()
' from Gary Frieder on Woody's Lounge
' modified with error handler & multiple bookmark handler by Charles Kenyon
'
' Add to context menus
Dim iBookCount As Integer   'number of bookmarks
Dim iCount As Integer       'counter for loop
Dim sName As String         'holds bookmark name in loop
'
On Error GoTo NoBookMark
    iBookCount = Selection.Bookmarks.Count
    If iBookCount > 1 Then
        For iCount = 1 To iBookCount
            sName = Selection.Bookmarks(iCount).Name
            MsgBox Prompt:="The selection is in " & iBookCount & "
bookmarks!" _
                & vbCrLf & "The name of bookmark No." & iCount & " is " _
                & sName & ".", _
                Buttons:=vbInformation, Title:="Multiple Bookmarks Names"
        Next iCount
        Exit Sub
    End If
    MsgBox Prompt:="The bookmark's name is " _
        & Selection.Bookmarks(1).Name & ".", _
        Buttons:=vbInformation, Title:="Bookmark Name"
    Exit Sub
NoBookMark:
    MsgBox Prompt:="There is no bookmark here.", _
        Title:="Sorry!", Buttons:=vbExclamation
End Sub

--
Charles Kenyon

Word New User FAQ & Web Directory:
<URL: http://www.addbalance.com/word/index.htm>

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide)
<URL: http://www.addbalance.com/usersguide/index.htm>

See also the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
 --------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.


Quote:
> Hi Bob,

> Try this

> Selection.GoToNext What:=wdGoToBookmark

> --
> Regards
> Jonathan West - Word MVP
> MultiLinker - Automated generation of hyperlinks in Word
> Conversion to PDF & HTML
> http://www.multilinker.com
> Word FAQs at http://www.multilinker.com/wordfaq
> Please post any follow-up in the newsgroup. I do not reply to Word
questions
> by email



> > --
> > Bob Lohse

> > Does anyone know how to find the Next bookmark in the document without
> > explicitly specifying its' name using VBA in a macro?  In other words,
if
> I
> > am at insertion point A and beyond it there is a book mark, I want to
move
> > the insertion point to the bookmark and read what the bookmark is.  If
> there
> > are no more bookmarks, it should return a false.



Mon, 24 May 2004 06:05:07 GMT  
 word bookmarks
The GoToNext method would be the easy way, but it doesn't
work properly. (It won't accept the parameter that should
be used according to the help file.)

The following sub collapses the current selection to its
starting position, and then creates a range whose starting
position is at the insertion point and whose end point is
at the end of the document. Finally, the sub tests the
Bookmarks collection of the range to see if there are any
bookmarks available.

Sub FindNextBookmark()
Dim r As Range
Dim b As Bookmark
Selection.Collapse Direction:=wdCollapseStart
Set r = ActiveDocument.Range(Start:=Selection.Start, _
End:=ActiveDocument.Content.End)

With r
    If .Bookmarks.Count > 0 Then
        Set b = .Bookmarks(1)
        'Now do what you want with the bookmark.
        'For example, select it:
        b.Select
    Else
        MsgBox "There are no more bookmarks " & _
        "in the document"
    End If
End With

End Sub

Quote:
>-----Original Message-----

>--
>Bob Lohse

>Does anyone know how to find the Next bookmark in the
document without
>explicitly specifying its' name using VBA in a macro?  In
other words, if I
>am at insertion point A and beyond it there is a book

mark, I want to move
Quote:
>the insertion point to the bookmark and read what the

bookmark is.  If there
Quote:
>are no more bookmarks, it should return a false.

>.



Fri, 28 May 2004 21:42:49 GMT  
 word bookmarks
I discovered an error in my previous code example. If you
want to select the first bookmark after the current
selection, it is best to collapse the current selection to
its end point -- otherwise the Select method will select
the same bookmark several times (clearly undesirable!).

In other words:

Instead of

   Selection.Collapse Direction:=wdCollapseStart

use

   Selection.Collapse Direction:=wdCollapseEnd

Stefan

Quote:
>-----Original Message-----
>The GoToNext method would be the easy way, but it doesn't
>work properly. (It won't accept the parameter that should
>be used according to the help file.)

>The following sub collapses the current selection to its
>starting position, and then creates a range whose
starting
>position is at the insertion point and whose end point is
>at the end of the document. Finally, the sub tests the
>Bookmarks collection of the range to see if there are any
>bookmarks available.

>Sub FindNextBookmark()
>Dim r As Range
>Dim b As Bookmark
>Selection.Collapse Direction:=wdCollapseStart
>Set r = ActiveDocument.Range(Start:=Selection.Start, _
>End:=ActiveDocument.Content.End)

>With r
>    If .Bookmarks.Count > 0 Then
>        Set b = .Bookmarks(1)
>        'Now do what you want with the bookmark.
>        'For example, select it:
>        b.Select
>    Else
>        MsgBox "There are no more bookmarks " & _
>        "in the document"
>    End If
>End With

>End Sub

>>-----Original Message-----

>>--
>>Bob Lohse

>>Does anyone know how to find the Next bookmark in the
>document without
>>explicitly specifying its' name using VBA in a macro?  
In
>other words, if I
>>am at insertion point A and beyond it there is a book
>mark, I want to move
>>the insertion point to the bookmark and read what the
>bookmark is.  If there
>>are no more bookmarks, it should return a false.

>>.

>.



Sat, 29 May 2004 18:51:14 GMT  
 word bookmarks
Hi Stefan,

I would appreciate it if you would not change the subject line when
continuing a thread. Especially the way the Microsoft server has been acting
lately, doing that messes up threads in my newsreader and I can't connect
your responses to the underlying conversation/question. (It was about a year
ago that John McGhie made the same request of me. I liked to change them so
they more accurately reflected the message content, as I think you are
trying to do.)

Thanks in advance.
--
Charles Kenyon

Word New User FAQ & Web Directory:
<URL: http://www.addbalance.com/word/index.htm>

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide)
<URL: http://www.addbalance.com/usersguide/index.htm>

See also the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
 --------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.


Quote:
> I discovered an error in my previous code example. If you
> want to select the first bookmark after the current
> selection, it is best to collapse the current selection to
> its end point -- otherwise the Select method will select
> the same bookmark several times (clearly undesirable!).

> In other words:

> Instead of

>    Selection.Collapse Direction:=wdCollapseStart

> use

>    Selection.Collapse Direction:=wdCollapseEnd

> Stefan

> >-----Original Message-----
> >The GoToNext method would be the easy way, but it doesn't
> >work properly. (It won't accept the parameter that should
> >be used according to the help file.)

> >The following sub collapses the current selection to its
> >starting position, and then creates a range whose
> starting
> >position is at the insertion point and whose end point is
> >at the end of the document. Finally, the sub tests the
> >Bookmarks collection of the range to see if there are any
> >bookmarks available.

> >Sub FindNextBookmark()
> >Dim r As Range
> >Dim b As Bookmark
> >Selection.Collapse Direction:=wdCollapseStart
> >Set r = ActiveDocument.Range(Start:=Selection.Start, _
> >End:=ActiveDocument.Content.End)

> >With r
> >    If .Bookmarks.Count > 0 Then
> >        Set b = .Bookmarks(1)
> >        'Now do what you want with the bookmark.
> >        'For example, select it:
> >        b.Select
> >    Else
> >        MsgBox "There are no more bookmarks " & _
> >        "in the document"
> >    End If
> >End With

> >End Sub

> >>-----Original Message-----

> >>--
> >>Bob Lohse

> >>Does anyone know how to find the Next bookmark in the
> >document without
> >>explicitly specifying its' name using VBA in a macro?
> In
> >other words, if I
> >>am at insertion point A and beyond it there is a book
> >mark, I want to move
> >>the insertion point to the bookmark and read what the
> >bookmark is.  If there
> >>are no more bookmarks, it should return a false.

> >>.

> >.



Mon, 31 May 2004 05:06:01 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Word - Bookmarks

2. Word Bookmarks, Userforms and Updates

3. word bookmarks

4. Word Bookmarks

5. Please help with text box to word bookmark

6. Converting Word BookMarks to PDF Files

7. copy an excel chart to word bookmark in vb

8. WORD bookmark text not printing from VB only on certain PC's

9. word bookmarks

10. Word bookmarks, filling from VBScript, apostrophe

11. Insert a Word BookMark from Access, How

12. assign values to Word bookmarks

 

 
Powered by phpBB® Forum Software