Log in

View Full Version : Inserting AutoText from Startup Template in 2010



clhare
12-05-2012, 07:33 AM
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?

Sub InsertAutoText()

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

End Sub

gmaxey
12-05-2012, 09:09 PM
If your template is in fact loaded then this should work:

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

End Sub

clhare
12-06-2012, 06:47 AM
Works perfectly! Thanks!

Cheryl