Member of collection doesn't exist for a bookmark

  • Good morning


    In creating a report I use bookmarks to add string data from the loop in my code:


    The first bookmark below the first sub heading isn't being found in the collection


    I'm getting this error


    at



    I am a trainee and have tried everything I can possibly think of. Can anyone assist please?


    I look forward to hearing from you. Many thanks.


  • And the word document, ideally.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • I meant the document with the bookmarks.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Sorry, I should explain that the document provides the exercise I've to complete; I had to create the code from scratch which:=


    creates a document

    adds a heading plus 2 sub headings

    adds a bookmark below each sub heading

    then the code looks at any documents you have open and counts how many fields are in those documents

  • I don't know why but it has to do with collapsing rngReport before you add the second bookmark. You can still refer to activedocument.bookmarks("bmkReport1").Range but that bookmark is no longer part of rngReport.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • That's what I've been finding too Rory. It's been so frustrating because the bookmark is definitely there (Insert/Bookmarks and then GoTo the bookmark works). I'll try collapsing after adding the bookmark.


    Cheers

  • The bookmark is there, but it's not part of rngReport. If you check the start of rngReport you'll see it starts at the second bookmark, not at the start of the document.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Thank you Rory, I got it to work using ActiveDocument as you suggested. I truly appreciate you not giving me the answer because it's good for me to figure it out with a nudge in the right direction. You're a star!!


    Cheers


    Debra

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!