Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Aug 2005
    Location
    Malaysia
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    AutoText with Bookmark (Word 2003)

    Is that possible to use AutoText and insert using Bookmark or whatever instead of Selection.Range? If yes, How to do it? I search help and this forum and couldn't find it.
    Ok, I stored the AutoText in a template. I'm using userform (checkbox and radio buttons) to determine which text to be inserted at a specific location. But I only know how to insert AutoText with the cursor placement. I use AutoText because my paragraphs have different formatting and graphics.


    Anyone can guide me? Thanks a million!

    Regards,
    Lam

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

    Re: AutoText with Bookmark (Word 2003)

    You can use code like this:
    <code>
    ActiveDocument.AttachedTemplate.AutoTextEntries("M yAutoText").Insert _
    Where:=ActiveDocument.Bookmarks("Test").Range, RichText:=True
    </code>
    Note that this is one instruction, I used the line continuation character _ to break it into two lines.

  3. #3
    New Lounger
    Join Date
    Aug 2005
    Location
    Malaysia
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AutoText with Bookmark (Word 2003)

    Thanks Hans!

    Is that possible to update the AutoText that has been inserted? What I mean is after I insert the text using AutoText and Bookmark, I can call the userform using shortcut key (I know this as I read this in your previous thread), but my problem is it will insert a new text instead of replacing it since this method only insert text to a specific bookmark. I read about this DocProperty and DocVariable but does it support AutoText?

    One more doubt, AutoText only can be stored in a global template and not doc itself?

    Thanks!


    Regards,
    ck

  4. #4
    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: AutoText with Bookmark (Word 2003)

    I can answer the last part:

    > AutoText only can be stored in a global template and not doc itself?

    AutoText can be stored only in templates and not documents. For any particular document, valid sources of AutoText are: (1) the document's attached template, if any; (2) Normal.dot; and (3) Other global templates.

  5. #5
    New Lounger
    Join Date
    Aug 2005
    Location
    Malaysia
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AutoText with Bookmark (Word 2003)

    Thanks guys! Need some time to digest the code.

    Btw, since a same bookmark name cannot use in two places, any suggestion as in my document, the same AutoText will be inserted several times in different places? Any better way instead of keep on declaring new bookmark name?

  6. #6
    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: AutoText with Bookmark (Word 2003)

    Two comments:

    (1) Bookmarks can be a bit fragile and may be completely blown away by inserting AutoText to them. You need to reestablish them to make sure they are there in case the insertion needs to happen again. Here is some sample code that does that:
    <UL><code>Sub TEST_InsertAutoTextToBookmark()
    InsertAutoTextToBookmark ActiveDocument.Bookmarks("bkTitle"), _
    NormalTemplate.AutoTextEntries("awesome")
    End Sub

    Sub InsertAutoTextToBookmark(bkmk As Word.Bookmark, _
    atEntry As Word.AutoTextEntry)
    ' Insert AutoText and then re-create destroyed bookmark
    Dim strBkmkName As String, rngTemp As Word.Range
    strBkmkName = bkmk.Name
    Set rngTemp = atEntry.Insert(bkmk.Range, RichText:=True)
    ActiveDocument.Bookmarks.Add strBkmkName, rngTemp
    Set rngTemp = Nothing
    End Sub</code>
    [/list](2) To deal with multiple "same insertion" bookmarks, simply name them with numbers after, like client01, client02, etc. Then you can loop through all your bookmarks and insert to all the ones that start with client.

    Added: Actually, I wonder whether I just contradicted myself. If you blow away and re-add the bookmark, will that muck with the looping? Hmmm... some testing will be required to see whether it is reliable.

  7. #7
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: AutoText with Bookmark (Word 2003)

    If you need the same text to appear in multiple locations, bookmark the first, then use REF fields to repeat the text in the rest (eg: {REF BkMrkNm} or just {BkMrkNm} ). Via styles and/or the use of field switches, the way the bookmarked text appears in each location can be tailored to suit the needs at that point.

    To get the REF fields in the body of the document to update immediately after you update the bookmarked text, add the line:
    ActiveDocument.Fields.Update
    to your code.

    Cheers
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  8. #8
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: AutoText with Bookmark (Word 2003)

    <P ID="edit" class=small>(Edited by macropod on 24-Aug-05 23:03. Code correction and simplification. Better late than never!!)</P>hi ck,

    The answer to the first part also partly comes courtesy of Jefferson in <post#=164387>post 164387</post#>, which I've simplified:

    Sub UpdateBookMarkText()
    Dim BmkNm As String, strNewText As String
    Dim rngTemp As Range
    BmkNm = "Bookmark Name"
    strNewText = "New Bookmark Text"
    With ActiveDocument.Bookmarks
    If .Exists(BmkNm) Then
    Set rngTemp = ActiveDocument.Bookmarks(BmkNm).Range
    With rngTemp
    .Text = strNewText
    End With
    .Add BmkNm, rngTemp
    Else
    MsgBox "Bookmark " & BmkNm & " not found."
    End If
    End With
    Set rngTemp = Nothing
    End Sub


    The above macro replaces a specified bookmark with a new text string. Alternatively, if calling the macro with parameters for the bookmark
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

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