Results 1 to 7 of 7
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Code: Function lngRemoveBookmarks(strBkMk As Strin

    If you're going to play with bookmark function, you're going to end up creating lotsa bookmarks during testing, if at no other time, so you'll want to remove some or all of them.

    This utility function removes all those bookmarks whose initial portion matches the supplied string.

    The UnderTheHood command "cmd_RemoveAllBookmarks" is merely a call to this slave with a zero-length string ("").


    <pre>Public Function lngRemoveBookmarks(strBkMk As String) As Long
    ' Procedure : lngRemoveBookmarks
    ' Description: Remove all GENERIC bookmarks from the active document.
    ' By: Chris Greaves Inc.
    ' Inputs: STRING leading portion of identifiers (usually strcApplication)).
    ' Returns: LONG number of bookmarks removed.
    ' Assumes: Nothing
    ' Side Effects: None.
    ' Tested: By the calls below.

    Dim lngCount As Long
    lngCount = ActiveDocument.Bookmarks.Count
    Dim lngItem As Long
    For lngItem = ActiveDocument.Bookmarks.Count To 1 Step -1
    If Left$(ActiveDocument.Bookmarks(lngItem).Name, Len(strBkMk)) = strBkMk Then
    ActiveDocument.Bookmarks(lngItem).Delete
    Else
    End If
    Next lngItem
    lngRemoveBookmarks = lngCount - ActiveDocument.Bookmarks.Count
    'Sub TESTlngRemoveBookmarks()
    ' ActiveDocument.Words(1).Select
    ' With ActiveDocument.Bookmarks
    ' .Add Range:=Selection.Range, Name:="eraseme1"
    ' End With
    ' ActiveDocument.Words(3).Select
    ' With ActiveDocument.Bookmarks
    ' .Add Range:=Selection.Range, Name:="eraseme2"
    ' End With
    ' ActiveDocument.Words(5).Select
    ' With ActiveDocument.Bookmarks
    ' .Add Range:=Selection.Range, Name:="eraseme3"
    ' End With
    ' MsgBox lngRemoveBookmarks("eraseme") ' should be AT LEAST 3
    'End Sub
    End Function
    </pre>


  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code: Function lngRemoveBookmarks(strBkMk As Strin

    I saw you kelliel!


    > kelliel replied to your post on the VB / VBA board at the Woody's Lounge
    Here's a little tighter code:

    <pre>Public Sub DeleteAllBookmarks()

    Dim myBookmark As Bookmark

    For Each myBookmark In activedocument.Bookmarks
    myBookmark.Delete
    Next
    End Sub
    </pre>



    It's true that it's tighter, but I often use a prefix for an application's bookmarks, and want to delete just those.


    I'm glad you're getting something out of the back posts.

  3. #3
    kelliel
    Guest

    Re: Code: Function lngRemoveBookmarks(strBkMk As Strin

    That post was supposed to be deleted. After I posted it, I reread your code and found out that you were only deleting certain bookmarks, not them all.

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Code: Function lngRemoveBookmarks(strBkMk As Strin

    Hi Lawrence,

    The "activedocument" on your phantom posting caught my eye - are you working in Word 97? - I used to get this all the time and it used to drive me up a wall. Eventually I found out (accidentally) that I could get these to start coming in as "ActiveDocument" again by replacing my Normal.dot. (also, I haven't seen the problem since switching to Word 2000).

    Gary

    PS I'm enjoying your posts!

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code: Function lngRemoveBookmarks(strBkMk As Strin

    I know!

    I have "email notification of replies to your posts" turned on ("Edit Profile") and couldn't resist a playful "gotcha!".


    I raised this question a while back in Lounge Matters. I think I received several post-then-delete messages from Eileen - I got to see how her brain works as she posted a reply, improved it, improved it, ...

  6. #6
    kelliel
    Guest

    Re: Code: Function lngRemoveBookmarks(strBkMk As Strin

    I really don't care how it appears in the code, i.e., ActiveDocument or activedocument, just as long as it works. [img]/forums/images/smilies/smile.gif[/img]

  7. #7
    kelliel
    Guest

    Re: Code: Function lngRemoveBookmarks(strBkMk As Strin

    I almost always click on Preview/Attach a File first. Then I reread the post to which I am responding and my answer. This is done so I don't make boo boos like I did.

    Unfortunately, on that one I clicked Post It instead.

Posting Permissions

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