Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Bookmarks in Header (Word 2003)

    I have built a letterhead template. I open a new doc from the template via a macro. The macro also customizes 3 items in the header at 3 different bookmarks. I use the following typical line of code to write to each location:
    ActiveDocument.Bookmarks("ext").range.text="2343"
    This works fine. The doc stays in Print view all the time as it is supposed to.
    I am writing another macro to return to the existing document and change those same values set at doc opening time and I cannot figure how to do it. If I use code ActiveDocument.Bookmarks("ext").select ,then the view changes from Print to Normal and this is not acceptable.
    When I check the bookmark, it does not include the text that was originally added.
    Can I add the original text to the bookmark, delete that text, enter the new text and write it back to the bookmark location? Is there another better approach?
    Help would greatly be appreciated. Thanks

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Bookmarks in Header (Word 2003)

    You can add text to the bookmark by using the syntax you first showed. Just avoid using .Select if you want to avoid changing the selection.

    StuartR

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Bookmarks in Header (Word 2003)

    Couple years ago I hacked around at replacing the text in a bookmark without deleting the bookmark itself and found it difficult to do. See <post#=164387>post 164387</post#> for a sort of workaround that inserts new text in the beginning of a bookmark, and then deletes the old. Because it uses only range objects, it should not change the View. Does this help?

  4. #4
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bookmarks in Header (Word 2003)

    Editing bookmarks can be truly maddening. I found this technique easier:

    <pre>Dim rng As Range
    Dim bk As Bookmark
    Dim bkname As String
    Set bk = ActiveDocument.Bookmarks(1)
    Set rng = bk.Range
    bkname = bk.Name
    rng.Text = "My new bookmark text"
    rng.Parent.Bookmarks.Add Name:=bkname, Range:=rng
    </pre>


  5. #5
    2 Star Lounger
    Join Date
    Jan 2001
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bookmarks in Header (Word 2003)

    Thank you for the suggestions. I will try working with the range statements tomorrow and avoid changing the selection.
    Can anyone explain what is going on when I execute the statement ActiveDocument.Bookmarks("ext").select. This is directed to a bookmark in the Header.
    It is the resulting view that is very unknown to me.
    Originally the doc was in print view but after the statement executes, the view changes to Normal with the header showing in another window at the bottom of the screen. What is this screen at the bottom? I cannot make it appear except through this VBA statement.
    When I am in Normal view and go to View the Header/Footer with mouse or keyboard commands, Word automatically goes back to Print view and opens the Header.

  6. #6
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bookmarks in Header (Word 2003)

    It's just a "split" window. You can remove it by going to Window -> Remove split.

    I've never had occassion to select a bookmark in a header before, and haven't seen that particular view. I was unable to manually re-create it. Interesting.

  7. #7
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Bookmarks in Header (Word 2003)

    I don't think it is "just" a split window. It looks to me like the Header view that we used to get with Word 95 (or maybe word 97). It has a toolbar with various header related controls, and a close button.

    I'm sure that I have seen this view in Word 2002 without using VBA to get there, but I can't remember how. I also vaguely remember that there is a way to get comments to show in a similar split window, but can't remember how this is done either.

    If my memory returns I'll come back and add the details.

    StuartR

  8. #8
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Bookmarks in Header (Word 2003)

    This code creates the view of the header or footer in a normal view window. As you can see, I thought it would be useful once upon a time but it is more an oddity than anything else.
    '================================================= ==========
    Sub ViewNormHeader()
    ' Macro created 27/11/98 by Andrew Lockton
    ActiveWindow.View.SplitSpecial = wdPaneCurrentPageHeader
    Windows.Arrange ArrangeStyle:=wdTiled
    End Sub
    '================================================= ==========
    Sub ViewNormFooter()
    ' Macro created 27/11/98 by Andrew Lockton
    ActiveWindow.View.SplitSpecial = wdPaneCurrentPageFooter
    Windows.Arrange ArrangeStyle:=wdTiled
    End Sub
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  9. #9
    2 Star Lounger
    Join Date
    Jan 2001
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bookmarks in Header (Word 2003)

    Edited to add <!t><!/t> and <!t><!/t> tags to make link active, see <!help=19>Help 19<!/help> - Mod


    Thanks to everyone. Using the code associated with ranges is working just as I require it. There is no more screen changing and it runs much faster.
    In following up some of your suggestions, I found an article about bookmarks by Ibby on the MVP site at http://word.mvps.org/FAQs/MacrosVBA/...hBookmarks.htm
    Ibby's explicit and concise article talking about placeholder and enclosing bookmarks finally turned all the lights on. Dave Rado has a good article also . Interestingly they both arrive at the same solution with code using the range object, as was also provided here.
    This has been my first experience using range codings. I must become more familiar with using them.
    Thanks again

Posting Permissions

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