edit existing autotext entries

  • Thread starter Allan Rees-Bevan
  • Start date
A

Allan Rees-Bevan

Using Word XP VBA or VB, how can I programmatically edit
an existing autotext entry in Normal.dot?

i.e we have an entry called Dublin which has our Dublin
office details. Our office details have now changed, so
we want to change the autotext entry in normal.dot to
reflect the new details. The only results I keep on
finding all deal with Selection.Range which we won't have
in this case.

Additionally, is there any way to manipulate/set the
range.text value?

Much appreciated,
Allan
 
J

Jay Freedman

Hi, Allan,

Word doesn't let you modify existing autotext entries, either in VBA or
through the dialog interface. You have to insert the old entry in a
document, modify it there, and then add an autotext entry with the same name
so that it replaces the existing one. Here's a sample macro that uses a
temporary blank document to hold the entry for editing, and uses
Find/Replace to make the change:

Sub ModifyAutoText()
Dim ATName As String
Dim OldText As String
Dim NewText As String
Dim TempDoc As Document
Dim oRg As Range

ATName = "DublinOffice"
OldText = "3 Shore Road"
NewText = "570 Fornance Street"

Set TempDoc = Documents.Add
Set oRg = TempDoc.Range

NormalTemplate.AutoTextEntries(ATName).Insert _
Where:=oRg, RichText:=True
Set oRg = TempDoc.Range
With oRg.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = OldText
.Replacement.Text = NewText
.Format = False
.Forward = True
.Wrap = wdFindStop
.Execute Replace:=wdReplaceAll
End With

Set oRg = TempDoc.Range
' exclude final paragraph mark
oRg.MoveEnd unit:=wdCharacter, Count:=-1
NormalTemplate.AutoTextEntries.Add _
Name:=ATName, Range:=oRg

Set oRg = Nothing
TempDoc.Close savechanges:=wdDoNotSaveChanges
Set TempDoc = Nothing
End Sub
 
C

Cindy M -WordMVP-

Hi Allan,

If all you want to do is change TEXT in an AutoText entry,
that's certainly possible:

NormalTemplate.AutoTextEntries(index).Value = "string"

Just tested, and it worked fine...
Using Word XP VBA or VB, how can I programmatically edit
an existing autotext entry in Normal.dot?

i.e we have an entry called Dublin which has our Dublin
office details. Our office details have now changed, so
we want to change the autotext entry in normal.dot to
reflect the new details. The only results I keep on
finding all deal with Selection.Range which we won't have
in this case.

Additionally, is there any way to manipulate/set the
range.text value?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep
30 2003)
http://www.mvps.org/word

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

Jay Freedman

Thanks, Cindy, I learned something today. :)

Cindy M -WordMVP- said:
Hi Allan,

If all you want to do is change TEXT in an AutoText entry,
that's certainly possible:

NormalTemplate.AutoTextEntries(index).Value = "string"

Just tested, and it worked fine...


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep
30 2003)
http://www.mvps.org/word

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

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