Check the existence of a certain bookmark

A

andreas

Dear Experts:

I would like to check whether...
.... a bookmark with the bookmark name 'Version' exists in the current
document.
If 'YES' the macro is to continue, if 'NO' a MsgBox is to say, that
the Bookmark 'Version' is missing and the subroutine is to exit.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
 
T

Tony Jollans

One way ...

Dim R As Word.Range
On Error Resume Next
Set R = ActiveDocument.Bookmarks("yourbookmarkname").Range
On Error GoTo 0
If R Is Nothing Then
MsgBox "Not found"
Exit Sub
End If
' more code if the bookmark exists
 
H

Harold Druss

andreas said:
Dear Experts:

I would like to check whether...
... a bookmark with the bookmark name 'Version' exists in the current
document.
If 'YES' the macro is to continue, if 'NO' a MsgBox is to say, that
the Bookmark 'Version' is missing and the subroutine is to exit.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

Another solution

If ActiveDocument.Bookmarks.Exists("Harry") Then
'do something
Else
MsgBox "Bookmark does not exist"
End If
 
A

andreas

One way ...

Dim R As Word.Range
On Error Resume Next
Set R = ActiveDocument.Bookmarks("yourbookmarkname").Range
On Error GoTo 0
If R Is Nothing Then
    MsgBox "Not found"
    Exit Sub
End If
' more code if the bookmark exists

--
Enjoy,
Tony

 www.WordArticles.com

Hi Tony,

thank you very much for your great support.

Regards, Andreas
 
A

andreas

Another solution

If ActiveDocument.Bookmarks.Exists("Harry") Then
    'do something
Else
    MsgBox "Bookmark does not exist"
End If

Hi Harold,

thank you very much for your great help. It works.

Regards, Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top