PDA

View Full Version : Add new autocorrect entry then send to a file



akuini
03-28-2012, 06:48 PM
I know how to print all Autocorrect Entry to a document. But what I need is when I add some new Autocorrect Entry in a session, Word copies those entries to a text file.
Is there a way to do that using VBA macro?

Related to the problem, is there an Autocorrect event?

fumei
03-28-2012, 08:14 PM
There is no AutoCorrect event, and therefore no, WHEN you add a new AutoCorrect there is no automatic (event driven) way to post AutoCorrect entries to a text file.

CAN you generate a text file of AutoCorrect entries? Yes.Sub AutoToTextfile()
Dim AC As AutoCorrectEntry
Dim NewDoc As Document
Set NewDoc = Documents.Add
For Each AC In Application.AutoCorrect.Entries
Selection.TypeText AC.Name & vbTab & AC.Value & vbCrLf
Next
With NewDoc
.SaveAs FileName:="c:\temp\AutoCorrect.txt", fileformat:=wdFormatText
.Close
End With
Set NewDoc = Nothing
End Sub
The code makes a new document, types each entry name, a Tab, and its value, then saves the file as a text file to C:\temp - adjust the path to suit.

E.g.

abbout about
abotu about
abouta about a
aboutit about it
aboutthe about the
abscence absence
accesories accessories

N.B. with NO added autocorrect entries (that is, with just the standard ones) the text file runs to 17 pages. You may want to consider doing this for Excel.

akuini
03-28-2012, 08:56 PM
Hi, Fumei
Thanks for the quick reply.
So there is no AutoCorrect event. I wonder why Microsoft doesn't create this event.

Mostly I use AutoCorrect entries to shorten a lot of phrases or technical terms. This means I do not use it to correct typing errors. The problem is when the entries get bigger, it will be difficult to memorize. I want the new entries stored in a file and then use it to memorize them.


Thanks for the code, I'll try it later.

fumei
03-28-2012, 09:26 PM
So there is no AutoCorrect event. I wonder why Microsoft doesn't create this event. There are actually very few codable events in Word...considering.

I can think of many more important events that it would be nice if they existed. Entering a table. Entering a cell. Even something like going into a header - THAT would it make easy as pie to protect changes in there.Sub OpenHeader()
Select Case environs(username)
Case "fumei"
' do whatever to the header
Case Else 'anyone else = NOT fumei
msgbox "Headers are not user editable."
End Select
End Sub

And on and on. A formfield_Change event. A create table event. And on and on.

Alas, like your AutoCorrect add event...it is not going to happen. Microsoft does not have a programming attitude towards making the object model more open. HEY! They took FileSearch away from us. And for no good reason...other than to satisfy pofessional programmers who do not like "users" to have easy access to the operating/file system. I am still ****ed they took away FileSearch!

MacroShadow
03-29-2012, 10:09 PM
I am still ****ed they took away FileSearch!

I recently posted a class to replace Application.FileSearch at http://www.vbaexpress.com/forum/showpost.php?p=263796&postcount=5
(http://www.vbaexpress.com/forum/showpost.php?p=263796&postcount=5)