Autocorrect - need Formatted option?

J

Joacim

Hi everyone,
I found this great code from Gregy Maxey/Doug Robbins. I didmy 2 col table
and it throws it into Autocorrect in less time than it takes to blink. But
I would like to add a few formatted entries. I realise that is a little more
complex? I did attempt to do true/false but it was over my head).

Any ideas if it can be done easily?

Sub MultiAutoCorrectGenerator()
'Adapted by Greg Maxey from MultiFindAndReplace code
'provided by Doug Robbins
Dim oDoc As Document
Dim i As Integer
Dim Wrong As Range
Dim Right 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 Wrong = oDoc.Tables(1).Cell(i, 1).Range
Wrong.End = Wrong.End - 1
Set Right = oDoc.Tables(1).Cell(i, 2).Range
Right.End = Right.End - 1
AutoCorrect.Entries.Add Name:=Wrong, Value:=Right
End If
Next i
End Sub
 
J

Jezebel

AutoCorrect can't handle formatting. If you want formatting you need to use
AutoText instead --

Sub MultiAutoTextGenerator()

Dim i As long

With Selection.Tables(1)
For i = 2 To .Rows.Count
ActiveDocument.AttachedTemplate.AutoTextEntries.Add _
Name:=ActiveDocument.Range(.Cell(i,1).Range.Start,
..Cell(i,1).Range.End - 1), _
Range:=ActiveDocument.Range(.Cell(i,2).Range.Start,
..Cell(i,2).Range.End - 1)
Next
end with

End Sub
 
J

Jay Freedman

For the formatted entries, replace the line

AutoCorrect.Entries.Add Name:=Wrong, Value:=Right

with

AutoCorrect.Entries.AddRichText Name:=Wrong, Range:=Right

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

Joacim

I feel like a ...... SO.... GOOD. Works a treat.

Jay Freedman said:
For the formatted entries, replace the line

AutoCorrect.Entries.Add Name:=Wrong, Value:=Right

with

AutoCorrect.Entries.AddRichText Name:=Wrong, Range:=Right

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

Joacim

Jezebel - works great. I'm using BOTH.
Jezebel said:
AutoCorrect can't handle formatting. If you want formatting you need to
use AutoText instead --

Sub MultiAutoTextGenerator()

Dim i As long

With Selection.Tables(1)
For i = 2 To .Rows.Count
ActiveDocument.AttachedTemplate.AutoTextEntries.Add _
Name:=ActiveDocument.Range(.Cell(i,1).Range.Start,
.Cell(i,1).Range.End - 1), _
Range:=ActiveDocument.Range(.Cell(i,2).Range.Start,
.Cell(i,2).Range.End - 1)
Next
end with

End Sub
 
J

Joacim

Hi Jay,

Works great 2003 and I assume backwards too.

But doesn't work in 2007 - I am guessing the VBA code has been BLOCKED so to
speak? Or is it XML based?

Has anyone looked into this as yet?

Joacim
 
J

Joacim

Disregard - it worked fine- just had a different order?

Thank you - saves me a lot of work...
 

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