Inserting every Autotext entry into Document

L

Lee

I want to insert all autotext entries into one document
with a page break between each autotext entry. I need to
have each autotext on a page of it's own for record
keeping purposes and I do not want to have to insert these
manually. Does anyone know how to do this?

Cheers
lee
 
C

Charles Kenyon

Have you tried simply printing the AutoText entries? Change "Print what?" on
the Print dialog to AutoText entries. Not sure this will give you one per
page but it will print them. One per page is going to be a lot of pages, or
at least it would be on my system.
 
L

Lee

Hi Charles
I've done that but it prints one after the other. For
filing purposes, I needed them one to each page - I know
it's going to take up a lot of pages but this is needed.
Never mind...
Cheers
lee
 
D

Doug Robbins - Word MVP

Use:

Dim i As Long, myrange As Range
For i = 1 To NormalTemplate.AutoTextEntries.Count
ActiveDocument.Range.InsertAfter NormalTemplate.AutoTextEntries(i).Name
& " - " & NormalTemplate.AutoTextEntries(i).Value
Set myrange = ActiveDocument.Range
myrange.Collapse wdcollapseeng
myrange.InsertBreak
Next i


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
C

Charles Kenyon

The following does _not_ work but may give you a start:

Sub ListAutoTextEntries()

Dim oAddIn As AddIn
Dim oTemplate As Template
Dim oATEntry As AutoTextEntry
Dim intCount As Integer
Dim strTemplateName As String

intCount = Application.AddIns.Count

If intCount > 0 Then
For Each oAddIn In Application.AddIns
strTemplateName = oAddIn.Path & "\" & oAddIn.Name
intCount = Templates(strTemplateName).AutoTextEntries.Count
If intCount > 0 Then
For Each oATEntry In Templates(strTemplateName) ' error message
generated
ATEntryInsert strTemplateName, oATEntry.Name
Next oATEntry
End If
Next oAddIn
End If

intCount = Application.Templates.Count
If intCount > 0 Then
For Each oTemplate In Application.Templates
strTemplateName = oTemplate.Path & "\" & oTemplate.Name
intCount = Templates(strTemplateName).AutoTextEntries.Count
If intCount > 0 Then
For Each oATEntry In Templates(strTemplateName)
ATEntryInsert strTemplateName, oATEntry.Name
Next oATEntry
End If
Next oTemplate
End If

End Sub

Sub ATEntryInsert(strTemplate As String, strATEntry As String)
Dim oTemplate As Template
Set oTemplate = Templates(strTemplate)
oTemplate.AutoTextEntries(strATEntry).Insert _
Selection.Range, _
RichText:=True
With Selection
.Move Unit:=wdParagraph
.InsertParagraphAfter
.Collapse Direction:=wdCollapseEnd
End With
Selection.InsertBreak Type:=wdPageBreak
Selection.Range.Collapse wdCollapseEnd
With Selection
.Move Unit:=wdParagraph
.InsertParagraphAfter
.Collapse Direction:=wdCollapseEnd
End With
End Sub

=====================
The following may help. It is a macro that creates a document with a table
containing all the AutoText entries in a particular Add-In. It works.

Sub GetAutoTextEntries()
Dim oTemplate As Template
Dim oEntry As AutoTextEntry
Dim iAutoTextCount As Integer
Dim sAutoTextEntry As String
Set oTemplate = Application.Templates("C:\Data\MS Office User System
Files\Utilities\KenyonMasterAdd-In01.dot")
iAutoTextCount = oTemplate.AutoTextEntries.Count
Application.ScreenUpdating = False
Application.Documents.Add
ActiveDocument.Tables.Add Range:=ActiveDocument.Range(Start:=0, End:=0),
NumRows:=1, NumColumns:=2
ActiveDocument.Tables(1).Rows(1).Cells(1).Select
Selection.Text = "AutoText Name"
ActiveDocument.Tables(1).Rows(1).Cells(2).Select
Selection.Text = "AutoText Entry"
' ActiveDocument.Tables(1).Rows(1).HeadingFormat = True
ActiveDocument.Tables(1).Rows.Add
' ActiveDocument.Tables(1).Rows.Last.Cells(1).Range.Text = "1"
For Each oEntry In oTemplate.AutoTextEntries
sAutoTextEntry = oTemplate.AutoTextEntries(oEntry.Index).Name
ActiveDocument.Tables(1).Rows.Last.Cells(1).Range.Text =
sAutoTextEntry
ActiveDocument.Tables(1).Rows.Last.Cells(2).Range.Select
Selection.Collapse
oEntry.Insert Where:=Selection.Range, RichText:=True
If oEntry.Index < iAutoTextCount Then
ActiveDocument.Tables(1).Rows.Add
End If
Next oEntry
Application.ScreenUpdating = True
Application.ScreenRefresh
End Sub

(That particular Add-In has 240+ AutoText entries.) Jay Freedman has a
corresponding template with code to load all of the items in a two-column
table into a template as AutoText.

Anyway, past my bedtime. Hope this gives you a start.
 
C

Charles Kenyon

Use Doug Robbins' method. You may or may not pick up something from these
bones if your AutoText is in multiple templates.
 
L

Lee

Hi Charles and Doug

I really appreciate your help. Wish I knew VBA to the
extent that you two do. The code from Doug works!!!
Thanks
Lee
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top