Results 1 to 11 of 11
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Pasting *inside* a bookmark (Word 2003 onwards)

    Text can be within a bookmark as well as next to it, or against it - so how do you command VBA to do so? Just using "AtE.Insert where:=ActiveDocument.Bookmarks("Autotemp").range, Richtext:=True" pastes next to it ...

    Many thanks in advance!
    Beryl M


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

    Re: Pasting *inside* a bookmark (Word 2003 onwards)


  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Pasting *inside* a bookmark (Word 2003 onwards)

    Alternatively, anyone got a better idea for how to contain a block of text/graphics etc as it is pasted into a document, so that it can be removed again cleanly by cutting it immediately afterwards, even if it was pasted into the middle of a document?
    Beryl M


  4. #4
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Pasting *inside* a bookmark (Word 2003 onwards)

    Thanks, Hans, but the problem wasn't that the bookmark was deleted (it was still there), but when I told Word to paste the text *inside* the bookmark it ignored me and pasted it next to it instead!

    I know you can make a selection and create/move a bookmark to surround the selection, but I need it to work the other way around - put the text inside the bookmark so I can select the bookmark and remove it again cleanly.

    Would it be possible to put a bookmark called 'start', paste the text etc then add a bookmark called 'end' and select from one bookmark to the other? Is that feasible?
    Beryl M


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

    Re: Pasting *inside* a bookmark (Word 2003 onwards)

    The insert method of an AutoTextEntry object returns a Range object. You can use this to delete the range later on, or you can set a bookmark to this range:

    Dim rng As Range
    Set rng = AtE.Insert(Where:=ActiveDocument.Bookmarks("Autote mp").Range, RichText:=True)
    ...
    rng.Delete

    or

    Dim rng As Range
    Set rng = AtE.Insert(Where:=ActiveDocument.Bookmarks("Autote mp").Range, RichText:=True)
    ActiveDocument.Bookmarks.Add Name:="Autotemp", Range:=rng
    ...

  6. #6
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Pasting *inside* a bookmark (Word 2003 onwards)

    I'm not sure I understand this, Hans - does that mean that when you paste the contents of an Autotext entry into a document, it is marked in some way already, a way that Word can refer to in order to pick it up again? As if it had been pasted inside a bookmark?

    In which case, with your example, could something like this put the content of the Autotext entry into the clipboard?

    Dim rng As Range
    Set rng = AtE.Insert(Where:=ActiveDocument.Bookmarks("Autote mp").Range, RichText:=True)
    rng.cut

    (I don' t think that last line is correct, but can't think what it should be off the top of my head!)
    Beryl M


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

    Re: Pasting *inside* a bookmark (Word 2003 onwards)

    Yes. It can even be shortened to

    AtE.Insert(Where:=ActiveDocument.Bookmarks("Autote mp").Range, RichText:=True).Cut

  8. #8
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Pasting *inside* a bookmark (Word 2003 onwards)

    <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15> - so have we actually found a way to deal with Autotext that *doesn't* require it to be physically pasted into a document?! At least for this bit of the project?

    All you need is a bookmark that exists and you just sort of swoop in and straight out again without actually stopping on the way past?!

    <img src=/S/rofl.gif border=0 alt=rofl width=15 height=15> Love it!
    Beryl M


  9. #9
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Pasting *inside* a bookmark (Word 2003 onwards)

    PS I just tried it, and it works perfectly!

    Brilliant!
    Beryl M


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

    Re: Pasting *inside* a bookmark (Word 2003 onwards)

    But it does get inserted into a document, you just remove it immediately afterwards. There still isn't a way to get at the complete text without inserting the autotextentry into a document.

  11. #11
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Pasting *inside* a bookmark (Word 2003 onwards)

    Yes, but the user doesn't see it happen, the document doesn't notice and the text is unaffected - it even deletes the bookmark when you cut it! And since all I'm using this cut text for is a 'view only' text box of the content of the autotext that's perfect!

    Of course, I am still now going to have to work on the Search and replace version, but that will only happen in an empty document so it shouldn't be so problematical ... I hope ... <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Wish me luck!
    Beryl M


Posting Permissions

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