Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert AutoCorrect entries to AutoText 1

Status
Not open for further replies.

dotobi

Technical User
Mar 9, 2004
229
HK
Hi

This query was originally posted in the Office Forum ( but I have beed advised to move it here.

A user has created a long list of AutoCorrect entries that were supposed to be AutoText entries (Word 2002). Each entry begins with a '/' so the following code was created for me by Tek-Tips user 'fumei' to export the entries to AutoText:
-------------------------------------
CODE
Sub myAutoCorrect()
Dim myTemplate As Word.Template
Dim myAC As Word.AutoCorrectEntry
Set myTemplate = ActiveDocument.AttachedTemplate
For Each myAC In Application.AutoCorrect.Entries()
If Left(myAc.Name, 1) = "/" Then
Selection.TypeText myAC.Value & vbCrLf
With Selection
.Previous(Unit:=wdParagraph, Count:=1).Select
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
End With
myTemplate.AutoTextEntries.Add Name:=myAC.Name, _
Range:=Selection.Range
End If
Next
Set myTemplate = Nothing
End Sub
-------------------------------------

This has worked, but only the last line appears in the AutoText

For example:
Autocorrect Entry: "/123 Abc St" is "123 Abc Street*LONDON*SW18**BY FAX AND DX 020 7123 4567" (the '*'s are returns/new lines).

When converted to AutoText it is just "**BY FAX AND DX 020 7123 4567".

Any Suggestions?

Thanks
 
Interestingly, when the code is ran, all the text that does not make it to AutoText appears in the word document as text.

For Example:
Autocorrect Entry: "/123 Abc St" is "123 Abc Street*LONDON*SW18**BY FAX AND DX 020 7123 4567" (the '*'s are returns/new lines).

When converted to AutoText, "123 Abc Street*LONDON*SW18" appears in the word doc and "**BY FAX AND DX 020 7123 4567" appears in the AutoText entry.

Thanks
 
Ah, that is because my code only grabs the preceding paragraph. ONLY that one. If your entry has a paragraph mark in it - which of course makes the entry TWO paragraphs - then my code only picks up the last one. My fault, I did not think about multi-line entries.

I am REALLY busy right now. I post the fix in about an hour or so. It is not hard. You just need to check each incoming entry to see if it has a Chr(13) in it. A Chr(13) is the paragraph mark. If there is one in the entry, then adjust the pick up code - the one that is used for the AutoText - to pick up the full entry.

Would any entries have more than two paragraphs (lines)? Never mind, good practice demands that I check for everything. If someone else wants to fiddle with this in the next while, go right ahead. I should be back in a hour or so.

As for deleting them (the AutoCorrect entries)...no problem.

Gerry
 
Thankyou sooo much for all this gerry. Don't hassle yourself too much if you're busy. Please just do it when you get the chance. I'd have a go but my knowledge of VBA is ziltch.

Thanks

keV
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top