AutoText entries macro

M

Macro''er

Hi. I have 100 words I need to enter in the AutoText database in Word 2003.
Can I create a macro instead of entering one by one in the database. I have
a macro that i'm using for AutoCorrect (see code below). Can I do something
like this for the AutoText?

AutoCorrect.Entries.Add Name:= "AL", Value:="Alabama (AL)"
 
G

Greg Maxey

Make a two column table with headings "AutoText text" and "AutoText
Name"

Put the 100 words (one word or phrases per row) in the left hand
column. Put the names in the left hand column.

Run this code:

Sub MultiAutoTextGenerator()
Dim oDoc As Document
Dim i As Integer
Dim pEntryText As Range
Dim pEntryName As Range
Set oDoc = ActiveDocument
Selection.Tables(1).Cell(1, 1).Range.Select
Selection.Collapse
For i = 2 To oDoc.Tables(1).Rows.Count
If oDoc.Tables(1).Rows(i).Cells(1).Range.Characters.Count > 1 Then
Set pEntryText = oDoc.Tables(1).Cell(i, 1).Range
pEntryText.End = pEntryText.End - 1
Set pEntryName = oDoc.Tables(1).Cell(i, 2).Range
pEntryName.End = pEntryName.End - 1
oDoc.AttachedTemplate.AutoTextEntries.Add _
Name:=pEntryName, Range:=pEntryText
End If
Next i
End Sub

You could do better with your AutoCorrect code also. See:
http://gregmaxey.mvps.org/AutoCorrect_Generator.htm
 
H

Helmut Weber

Hi,
Hi. I have 100 words I need to enter in the AutoText database in Word 2003.
Can I create a macro instead of entering one by one in the database.

Yes. But it seems,
AutoTextEntries.add
expects not only a name, but a range in addition.

So you have to put up some kind of list
containing a name and an according range.

Sure, doable.
With only a hundred I don't know whether its economical for you.


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
J

Jay Freedman

Helmut said:
Hi,


Yes. But it seems,
AutoTextEntries.add
expects not only a name, but a range in addition.

So you have to put up some kind of list
containing a name and an according range.

Sure, doable.
With only a hundred I don't know whether its economical for you.

It's already done. Download http://jay-freedman.info/autotextloader2.zip and
follow the instructions.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
M

Macro''''er

Thank you so much! I'm loving this forum and learning so much from it!
Thank you and all the MVPs!
 
M

Macro''''er

Hi Jay,

It's me again. You don't by any chance have an autocorrect loader i can
use, do you?
 
G

Greg Maxey

Jay,

I am sorry. I was at work and forgot all about your excellent tool. In
fact the link I referenced was to my AutoCorrectGenerator that I adapted
from your code and posted last year.

I just updated my website to like to your AutoTextLoader from my
AutoCorrectGenerator tips page.

Cheers
 
M

Macro''''er

I did, but I am so new at this creating macro and I'm hoping I can download a
file just like the AutoTextLoader Jay provided. The download includes the
userform and all. Thank you!
 
J

Jay Freedman

M

Macro''''er

Thank you, it works really well!

I have another question...can I leverage the AutoText Back up document to
find and replace in my active document? Hope my question make sense.
 
J

Jay Freedman

To be honest, I can't quite grasp what you want to do. What does a
document full of AutoText entries have to do with Find/Replace? Can
you expand a bit on the purpose?

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
M

Macro''''er

Sure. I have a document with 2 columns that will consist of 500+ words or
phrase:

First column = Word ****(Plain text)
Second column = Word *******(formatted with bold, italics, with annotation)

I'm looking for a macro that will find the first column "Word" in my active
document and Replace with second column "Word" and format it Bold, Italics,
display the comment and with highlight.

Thank you and hope my request makes sense.
 
J

Jay Freedman

A macro like that would be possible, although I can't say without
trying it whether the comment/annotation would come along.

There would have to be some preliminary code in the macro to open the
document containing the replacements (assuming the document to be
modified is already open), and set up some variables.

The core of the code would be a loop that steps through the rows of
the replacements table. For each row, it would run an inner loop that
uses the Find property of a Range object to search the active document
for the text from the first column. Each time it's found, the code
would replace the found text with the contents of the second column,
using the Range object's .FormattedText property.

It wouldn't be very hard to program, but it isn't something you can
just throw together -- there are usually some fiddly bits that need
tweaking after you test it with the real data.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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