Consulting

Results 1 to 3 of 3

Thread: Inserting AutoText from Startup Template in 2010

  1. #1
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location

    Inserting AutoText from Startup Template in 2010

    I have a template that I have stored in the Program Files startup folder (and I've added that location to the Trust Locations in Word 2010). I have several AutoText entries stored in that template that I want to be able to access while in any Word 2010 document. I tried the following code, but it only works if I am in the "My Macros.dotm" file. I can insert the AutoText if I do it manually, but not through this macro (I get a runtime error that says the member of the collection doesn't exist).

    What do I need to do to get this macro to work for any document?

    [vba]Sub InsertAutoText()

    Application.Templates( _
    "C:\Program Files\Microsoft Office\Office14\STARTUP\My Macros.dotm" _
    ).BuildingBlockEntries("TestAT").Insert Where:=Selection.Range, _
    RichText:=True

    End Sub[/vba]

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    If your template is in fact loaded then this should work:

    [VBA]Sub InsertAutoText()
    Dim oTemp As Template
    Set oTemp = Application.Templates(ThisDocument.FullName)
    oTemp.BuildingBlockEntries("TestAT").Insert Where:=Selection.Range, _
    RichText:=True

    End Sub[/VBA]
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location
    Works perfectly! Thanks!

    Cheryl

Posting Permissions

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