Add Autotext entries to custom template

F

FMAS

I got part of this from discussion groups. It works fine: It reads
Autotext entries from a table and assign them to normal.dot.
I am trying to assign them to a custom template (eg "mytemplate.dot")
but no way to find the autotext entries in "Mytemplate.dot". I have
assigned the template to the document via Tools > Add-in etc..

Sub AddAutoTextEntries()
Dim oTemplate As Template

Dim tbl As Table

Dim lRow As Long
Dim lRowIx As Long
Dim strId As String

'Define oTemplate
Set oTemplate = ThisDocument.AttachedTemplate '## I have also tried
writing the actual path in full, didn't help

Set tbl = ActiveDocument.Tables(1)
lRow = tbl.Rows.Count
' Schleife über alle Zeilen
For lRowIx = 1 To lRow
' Kürzel auslesen
strId = tbl.Cell(lRowIx, 1).Range.Text
strId = Left$(strId, Len(strId) - 2)
' 2 Spalte auswählen
tbl.Cell(lRowIx, 2).Select
' 1 Schritt zurück, damit das
' Zell-Ende nicht markiert wird
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
' Autotext-Eintrag hinzufügen
oTemplate.AutoTextEntries.Add Name:=strId,
Range:=Selection.Range '## here is the problem, takes still normal.dot
Next lRowIx

End Sub
 
C

Cindy M.

Hi Fmas,
I got part of this from discussion groups. It works fine: It reads
Autotext entries from a table and assign them to normal.dot.
I am trying to assign them to a custom template (eg "mytemplate.dot")
but no way to find the autotext entries in "Mytemplate.dot". I have
assigned the template to the document via Tools > Add-in etc..
What happens when you try to run the code? Are you getting an error
message? On what line? What's the exact wording of the error message?

Note: The following line should read

Set oTemplate = ActiveDocument.AttachedTemplate '## I have also tried
writing the actual path in full, didn't help

ThisDocument refers to the document containing the macro code.
ActiveDocument is the document with the focus in Word.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
F

FMAS

Hi Fmas,


What happens when you try to run the code? Are you getting an error
message? On what line? What's the exact wording of the error message?

Note: The following line should read

 Set oTemplate = ActiveDocument.AttachedTemplate  '## I have also tried
writing the actual path in full, didn't help

ThisDocument refers to the document containing the macro code.
ActiveDocument is the document with the focus in Word.

Cindy Meister
INTER-Solutions, Switzerlandhttp://homepage.swissonline.ch/cindymeister(last update Jun 17 2005)http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)

Great Cindy! Thank you very much. That was my mistake. with
"ActiveDocument" it works as expected. Vielen Dank. Merci beaucoup.
 

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