How to all delete AutoCorrect entries

T

tomcat

Hi, I am looking for a way to delete all AutoCorrect entries from a Word
2000 or XP installation.

I have written the following code:

=========================================
Sub DeleteACentries ()

Dim lngACcorrect as Long
lngACcorrect = Application.AutoCorrect.Entries.Count

For I = 1 To lngACcorrect
Application.AutoCorrect.Entries(I).Delete
Next I
Application.ScreenUpdating = True
MsgBox ("Ready!")

End Sub
==========================================


The "For" loop executes several times without errors, but stops after
exactly half of the total number of entries (the value of lngACcorrect),
with the following error message:

"5941 Requested member of collection does not exist."

What am I doing wrong? Why does the process keep stopping halfway? Does
the problem have to do with the existence of columns in the AC list? How
can I overcome the problem?

Kind regards.

AND
 
D

Dave Lett

Hi,

It _should_ stop after exactly half. That is, if you delete an item from a collection, then the number of items is less by one. You can get around this by running through the collection in reverse, as in the following

Sub DeleteACentries ()

Dim lngACcorrect as Long
lngACcorrect = Application.AutoCorrect.Entries.Count

For I = lngACcorrect to 1 Step -1
Application.AutoCorrect.Entries(I).Delete
Next I
Application.ScreenUpdating = True
MsgBox ("Ready!")

End Sub


I think this will suit your needs.

HTH,
Dave
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Say there were 4 entries

After deleting the 1st one there would be 4 left
After deleting the 2nd one, there would be 2 left
Some when you are trying to delete the 3rd, there is no 3rd one.

You must use

For I = lngACcorrect To 1 Step - 1

Then the 1st one that is deleted would be the 4th,
The 2nd one would be the 3rd
The 3rd one would be the 2nd
The 4th one would be the 1st

--
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
 
A

and

YES!

Thanks, Dave and Doug. I was just starting to discover that my logic
wasn't so locical after all, and then your answers came. I have to count
down. That is all.

Thanks a bunch!
 
T

Theo van der Ster

Just for the sake of completeness, here's a way that doesn't involve counting:

For Each anentry In AutoCorrect.Entries
anentry.Delete
Next anentry

Regards,
Theo van der Ster
 
W

Word Heretic

G'day (e-mail address removed) (Theo van der Ster),

try

with autocorrectentries
while .count>0
.item(1).delete
wend
end with

- tis much faster

Steve Hudson
Word Heretic Sydney Australia
Tricky stuff with Word or words

Email: WordHeretic at tpg.com.au


Theo van der Ster was spinning this yarn:
 

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