Results 1 to 10 of 10
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Bookmark / Text box (Word 2002)

    We have text boxes placed in the first page and primary headers of some document templates so that we can add "stamps" to the document if the user wishes. These "stamps" would be text such as DRAFT, COPY, etc. The user can change and remove them with a macro which relies on a bookmark in each of the text boxes.

    Occasionally the bookmarks get removed. I'd like to be able to replace the bookmark to the text boxes, but I'm having a bit of trouble writing the code. I always know the index of the text box, which I am supposing to be the Shapes collection. Is that correct. Can anyone offer a suggestion on how to set a range in Shapes(x) so that I can add a bookmark?

    Thanks,
    Richard Barrett

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

    Re: Bookmark / Text box (Word 2002)

    When I needed to do something similar I set the Name property of the textbox, in the code that created it. I could then access it as Shapes("txtboxWatermark") or whatever name I had used.

    To access the range inside a textbox you use ActiveDocument.Shapes(n).TextFrame.TextRange.

    StuartR

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Bookmark / Text box (Word 2002)

    Many thanks. I'll give this a try.

    Richard

  4. #4
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Bookmark / Text box (Word 2002)

    That worked beautifully. Thanks again.

  5. #5
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Bookmark / Text box (Word 2002)

    After all the luck I had yesterday, I've hit a glitch today. I'm putting a bookmark into Shapes(4) of the first page header and another bookmark into Shapes(1) of the primary header. The bookmarks "landed" perfectly yesterday and again this morning. We tested this with a user who had a problem. Once I put the problem document on my system, I've had the same problem the user had... both bookmarks go into the first page header. My code is below; perhaps you can identify a problem with it. My question, however, is how to "name" a textbox when I crate it with code. I see properties for orientation, left, right, height, width and anchor. Can you assist me with the Name property?

    Thanks.

    Code I'm using that functioned well yesterday, but not today..
    With ActiveDocument
    Set rng1 = .Sections(1).Headers(wdHeaderFooterFirstPage).Shap es(4).TextFrame.TextRange
    .Bookmarks.Add "Watermark1", rng1

    Set rng2 = .Sections(1).Headers(wdHeaderFooterPrimary).Shapes (1).TextFrame.TextRange
    . Bookmarks.Add "Watermark2", rng2
    End With

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Bookmark / Text box (Word 2002)

    You can do something like this:

    With ActiveDocument.Shapes.AddTextbox(msoTextOrientatio nHorizontal, 10, 10, 300, 100, Selection.Range)
    .Name = "MyTextBox"
    ...
    End With

  7. #7
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Bookmark / Text box (Word 2002)

    Thank you, Hans. What appears to be happening is Word is combining the first and primary headers' shapes collections into a single collection. That's fine, if it were consistent. I think the best route is to use the names objects.

    Thanks agian.
    Richard

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Bookmark / Text box (Word 2002)

    Floating shapes in headers and footers are hard to work with because all headers and footers in the entire document share one collection of shapes. See <post#=167,988>post 167,988</post#> and <post#=157,050>post 157,050</post#> for examples of the complicated code you need to deal with this. It's slightly easier if you use inline shapes.

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

    Re: Bookmark / Text box (Word 2002)

    This is exactly why I recommended that you use a Named text box, it just makes everything so much easier.

    StuartR

  10. #10
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Bookmark / Text box (Word 2002)

    Yes... that really is the answer. I also realize that I can apply a name to an existing text box, which makes things easier all around.

    Thanks, Richard

Posting Permissions

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