Autotext copying using VBA

R

R. John

I want to programatically, using VBA, copy autotext
entries from a Normal-old.dot to Normal.dot

Having trouble finding method to accomplish this task.
 
D

Dave Lett

Hi,

From the VBA help file topic titled "OrganizerCopy Method":

Dim atEntry As AutoTextEntry

For Each atEntry In _
ActiveDocument.AttachedTemplate.AutoTextEntries
Application.OrganizerCopy _
Source:=ActiveDocument.AttachedTemplate.FullName, _
Destination:=NormalTemplate.FullName, Name:=atEntry.Name, _
Object:=wdOrganizerObjectAutoText
Next atEntry

HTH,
Dave
 
J

Jay Freedman

The method you're looking for is Application.OrganizerCopy. Here's an
example from the VBA Help for copying all the entries from one to another:

For Each aEntry In ActiveDocument.AttachedTemplate.AutoTextEntries
Application.OrganizerCopy _
Source:=ActiveDocument.AttachedTemplate.FullName, _
Destination:=NormalTemplate.FullName, Name:=aEntry.Name, _
Object:=wdOrganizerObjectAutoText
Next aEntry

For your purposes, you need to replace ActiveDocument.AttachedTemplate by a
Template object initialized to point to Normal-old.dot. If you want to copy
only specific entries, repeat the OrganizerCopy with different Name
parameters.

One other thing, which I keep harping on <g>, is that the examples in the
Help almost never declare the data types of their variables. In this
example, aEntry should be declared

Dim aEntry As AutoTextEntry
 
R

R. John

Thanks much! One last question,

does ActiveDocument.AttachedTemplate.AutoTextEntries
assume that my normal-old.dot is an attached template? No
where have I specifically attached this template to the
active document.
-----Original Message-----
The method you're looking for is
Application.OrganizerCopy. Here's an
example from the VBA Help for copying all the entries from one to another:

For Each aEntry In ActiveDocument.AttachedTemplate.AutoTextEntries
Application.OrganizerCopy _
Source:=ActiveDocument.AttachedTemplate.FullName, _
Destination:=NormalTemplate.FullName, Name:=aEntry.Name, _
Object:=wdOrganizerObjectAutoText
Next aEntry

For your purposes, you need to replace
ActiveDocument.AttachedTemplate by a
 
J

Jay Freedman

Sorry, I should have fully specified what I meant. In order to get at the
AutoTextEntries collection of the Normal-old.dot template, it has to be
attached to some document -- either the active document or a dummy document
created specifically for the purpose. Here's code that creates a document
(invisibly) on the Normal-old template and discards it at the end:

Sub CopyAutoText()
Dim aEntry As AutoTextEntry
Dim OldTemplate As String
Dim TempDoc As Document

OldTemplate = "Normal-old.dot"
Set TempDoc = Documents.Add(Template:=OldTemplate, _
Visible:=False)

For Each aEntry In TempDoc.AttachedTemplate.AutoTextEntries
Application.OrganizerCopy _
Source:=TempDoc.AttachedTemplate.FullName, _
Destination:=NormalTemplate.FullName, _
Name:=aEntry.Name, _
Object:=wdOrganizerObjectAutoText
Next aEntry

TempDoc.Close SaveChanges:=wdDoNotSaveChanges
Set TempDoc = Nothing
End Sub
 
C

Charles Kenyon

If you are using styles to organize your AutoText, copy the necessary styles
first.

Also, consider using a separate global template rather than normal.dot.

See http://addbalance.com/word/movetotemplate.htm for step-by-step
instructions on manually moving / sharing / copying customizations including
AutoText, AutoCorrect, keyboard assignments, macros, etc.
 
R

R. John

This is just the ticket. Thank you Jay.
-----Original Message-----
Sorry, I should have fully specified what I meant. In order to get at the
AutoTextEntries collection of the Normal-old.dot template, it has to be
attached to some document -- either the active document or a dummy document
created specifically for the purpose. Here's code that creates a document
(invisibly) on the Normal-old template and discards it at the end:

Sub CopyAutoText()
Dim aEntry As AutoTextEntry
Dim OldTemplate As String
Dim TempDoc As Document

OldTemplate = "Normal-old.dot"
Set TempDoc = Documents.Add(Template:=OldTemplate, _
Visible:=False)

For Each aEntry In TempDoc.AttachedTemplate.AutoTextEntries
Application.OrganizerCopy _
Source:=TempDoc.AttachedTemplate.FullName, _
Destination:=NormalTemplate.FullName, _
Name:=aEntry.Name, _
Object:=wdOrganizerObjectAutoText
Next aEntry

TempDoc.Close SaveChanges:=wdDoNotSaveChanges
Set TempDoc = Nothing
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP




.
 

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