none
My book mark is removed after header.range.delete() RRS feed

  • Question

  • My bookmark is automatically deleted after run header.Range.Delete().   I created bookmark at current cursor position and after that I run code to delete header and footer as follows

    Dim header As Word.HeaderFooter

          For Each header in Section.Headers

                header.Range.Delete()

          Next

          For Each header In section.Footers

               footer.range.delete()

          Next

    After that the bookmark I created is gone. How do I keep my bookmark after execute Header.Range.Delete()? 

    thanks in advance!

    Friday, July 27, 2012 2:08 PM

Answers

  • Stefan,

    Thanks for reply,

    I did not create bookmark inside of header. Is there any way where the bookmark is created? I want to check just in case.


                
    Are you saying that a bookmark in the main body of the document gets deleted when you run the macro? I can't explain that, unless there is more code than you have posted in this thread. Posting any such code would be helpful.

    Stefan Blom, Microsoft Word MVP
    • Edited by Stefan BlomMVP Friday, July 27, 2012 10:13 PM
    • Marked as answer by BLT123 Friday, August 10, 2012 1:24 PM
    Friday, July 27, 2012 7:39 PM

All replies

  • I'm assuming that the bookmark is inside a header or footer? Otherwise there's no reason why it should get deleted with the code you posted. What you can do is recreate the bookmark using code.


    Stefan Blom, Microsoft Word MVP

    Friday, July 27, 2012 3:04 PM
  • Stefan,

    Thanks for reply,

    I did not create bookmark inside of header.  Is there any way where the bookmark is created? I want to check just in case.

    Friday, July 27, 2012 7:37 PM
  • Stefan,

    Thanks for reply,

    I did not create bookmark inside of header. Is there any way where the bookmark is created? I want to check just in case.


                
    Are you saying that a bookmark in the main body of the document gets deleted when you run the macro? I can't explain that, unless there is more code than you have posted in this thread. Posting any such code would be helpful.

    Stefan Blom, Microsoft Word MVP
    • Edited by Stefan BlomMVP Friday, July 27, 2012 10:13 PM
    • Marked as answer by BLT123 Friday, August 10, 2012 1:24 PM
    Friday, July 27, 2012 7:39 PM
  • You can view a list of bookmarks in the document by going to the 'Insert' tab, and looking under the 'Links' group box, where you will find a 'Bookmarks' button.

    You can also make bookmarks visible. You go to File > Options > [It then depends which version you have. On Word 2013 it's under 'Advanced'].

    Finally, you can find bookmarks by name grammatically. Check MSDN for how to do this.

    Friday, July 27, 2012 7:47 PM
  • Hi BLT

    Please give us exact steps to reproduce the behavior you're seeing - including creating a test document and telling us exactly where you're creating the bookmark.

    Also, which version of Word is this?


    Cindy Meister, VSTO/Word MVP

    Saturday, July 28, 2012 1:29 PM
    Moderator