Determine if bookmark exists

R

Rogge

How do i determine if a bookmark exists? I know the IF
statement wiht the AND does not work, just here as an
example of the logic i wish to process...

If frmLogin.txtLogin(7) <> "" AND exists(wdNew.Bookmarks
("bkmEmpEmail")) Then

wdNew.Bookmarks("bkmEmpEmail").Range.Text = Chr(11) & "E-
Mail:" & Chr(9) & frmLogin.txtLogin(7)

Else

wdNew.Bookmarks("bkmEmpEmail").Range.Text = " "

End If
 
J

Jay Freedman

Hi, Rogge,

"Exists" is a method of the Bookmarks collection, not a function. The syntax
you need is

If frmLogin.txtLogin(7) <> "" And wdNew.Bookmarks.Exists("bkmEmpEmail")
Then

Once you get past the syntax error, you have a logic error: Suppose the
condition of the If statement is false because the bookmark doesn't exist.
The Else clause will execute and you'll get a runtime error ("the specified
member of the collection does not exist"). You can handle this with an
ElseIf clause to test one half of the And expression.
 

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