Results 1 to 3 of 3

Thread: WORD form/VBA issue - Urgent help req.

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Location
    Sydney
    Posts
    2

    WORD form/VBA issue - Urgent help req.

    Hi all - being a newbie I'll try and be quick. I'm having trouble debuging VBA in Word (2002 SP2).

    In a nutshell I'm trying to delete a bookmark - the bookmark is not being deleted and yet even in debug mode and stepping a line at a time I can see no error or issue.

    I'd really appreciate any suggestions as it is doing my head in - I've surfed the net and can't find any suggestions as well as reading the help, and two books. How can something so simple be so sdifficult to resolve?

    In debug mode all lines are peformed, but the bookmark remains!
    Cheers
    Colin.

    Sub checktest()
    On Error Resume Next
    If ThisDocument.Bookmarks.Exists("text") Then
    MsgBox "found test1 bookmark"
    ActiveDocument.Bookmark("text").Range.Delete
    MsgBox "after delete"
    End If
    End Sub

  2. #2

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Location
    Sydney
    Posts
    2
    It always happens - just when you ask for help you get one more last idea and what do you know - I was creating the bookmark incorrectly. Just a shame that VB allows this without any form of warning - it could find it but not delete it.
    Cheers anyway.

  3. #3
    Lively Member
    Join Date
    Jul 2002
    Posts
    78
    For future reference...


    To keep it "neat", check for the existence of the bookmark first and then delete it. You shouldn't need to use the range object when deleting bookmarks.

    To delete a bookmark in Word use the following (VB):

    VB Code:
    1. If .ActiveDocument.Bookmarks.Exists("BookmarkName") = True then
    2.     .ActiveDocument.Bookmarks("BookmarkName").Delete
    3. End if

    Note -- in VBA you don't need the period before ActiveDocument

    Good luck!
    Mary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width