Thread: Autotext in 2010
2013-05-07, 16:13 #1
- Join Date
- Feb 2002
- Auckland, New Zealand
- Thanked 0 Times in 0 Posts
Autotext in 2010
I developed several templates in Word 97 that inserted autotext at specified bookmarks. Now under 2010 I get this error
I have tried using Application.ActiveDocument but his does not work either. When I record a macro it shows the following:
Application.Templates("D:\Users\Public\Templates\S tartup\ianznorm.dotm"). _
BuildingBlockEntries("Voluntary").Insert Where:=Selection.Range, RichText _
Can anyone help as we have quite a few templates that use these referencescheers
Subscribe to our Windows Secrets Newsletter - It's Free!
Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!
+ Get this BONUS — free!
Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!
2013-05-07, 20:24 #2
- Join Date
- Jan 2001
- Melbourne, Victoria, Australia
- Thanked 141 Times in 134 Posts
Are you sure the building block is in that template? Your code points at a different entry than the one you recorded.
I don't know if this is the problem but with the 2007+ versions it is now possible to have lots of building blocks with the same name if their type and category aren't the same. For this reason, I am now a bit more specific about which building block I want to add to a document. The following code includes a line which demonstrates this. The rest of the code is useful for doing an audit of all the template building blocks.
Sub InsertAllTemplateBuildingBlocks() Dim i As Integer, oTemplate As Template, sName As String Set oTemplate = ActiveDocument.AttachedTemplate If oTemplate.BuildingBlockEntries.Count > 0 Then For i = 1 To oTemplate.BuildingBlockEntries.Count With oTemplate.BuildingBlockEntries.Item(i) sName = .Type.Name & " > " & .Category.Name & " > " & .Name Selection.TypeText "===================================" & vbCr & sName & vbCr oTemplate.BuildingBlockTypes(.Type.Index).Categories(.Category.Name).BuildingBlocks(.Name).Insert _ Where:=Selection.Range, RichText:=True Selection.TypeParagraph End With Next End If End Sub
Last edited by Andrew Lockton; 2013-05-07 at 20:42.Andrew Lockton, Chrysalis Design, Melbourne Australia