Results 1 to 2 of 2
  1. #1
    Star Lounger
    Join Date
    Jun 2005
    Thanked 0 Times in 0 Posts

    Autotext template (WordXP)

    I have a template in the startup folder that contains all the autotext entries for section breaks, text and tables.

    I have a macro to insert the autotext from the template. It types in the name of the autotext,selects it and then "selection.Range.InsertAutoText ". Therefore, I am not specifying the template that the autotext resides it.

    Sometimes the styles drop off in the tables. However, if I copy and paste the autotext into the document then it is fine. Is there a better way to insert autotext from the autotext template?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Silicon Valley, USA
    Thanked 93 Times in 89 Posts

    Re: Autotext template (WordXP)

    Is the macro in the global template? If so, you can use code like this. Note that I have a procedure that inserts up to 3 different autotext entries, so I centralize all the messy parts here:
    <pre>Sub InsertIntoContent(strATName As String, strATRange As Range)
    ' Created 10/04/2003 by Jefferson Scher

    ' Set up object references
    Dim atSource As Template, intCounter As Integer
    For intCounter = 1 To Templates.Count
    If Templates(intCounter).Name = MacroContainer.Name Then
    Set atSource = Templates(intCounter) ' Object ref to this template
    Exit For
    End If

    ' Insert the letter top autotext entry
    atSource.AutoTextEntries(strATName).Insert _
    Where:=strATRange, _

    ' Clean up objects
    If Not (atSource Is Nothing) Then Set atSource = Nothing
    End Sub</pre>

    As you can see, the macro first checks all the templates until it identifies the "macro container," i.e., the template from which it is running, and then creates an object reference to it so that in the next step, it can insert a specific autotext entry from that template. The range depends on the particular entry I'm inserting, but it could be Selection.Range if you like.

Posting Permissions

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