![]() |
|
|
|
#1
|
||||
|
||||
|
The difficulty with creating a function to perform an autocorrect on a text is in determining what to autocorrect. Auto correct entries can be longer than a word and can include punctuation which throws out the potential word count. The only solution I can see would be to select the text you wish you check against the autocorrect list and then run the macro - something like
Code:
Sub ApplyAutoCorrect()
Dim i As Long
Dim orng As Range
Set orng = Selection.Range
orng.MoveStartWhile Chr(32)
orng.MoveEndWhile Chr(32), wdBackward
If Len(orng) > 0 Then
For i = 1 To Word.Application.AutoCorrect.Entries.Count
If orng.Text = Word.Application.AutoCorrect.Entries(i).Name Then
Word.Application.AutoCorrect.Entries(i).Apply orng
Exit For
End If
Next i
End If
lbl_Exit:
Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#2
|
|||
|
|||
|
Thanks, I solved the problem of potential multiple words and various word terminators by just selecting text the size of each entry. Also "Option Compare Text" is needed to make it case-insensitive.
Option Compare Text Sub AutoCorrectNow() Dim orng As Range For Each Entry In Word.Application.AutoCorrect.Entries Set orng = Selection.Range orng.MoveStart wdCharacter, -Len(Entry.Name) If orng.Text = Entry.Name Then Entry.Apply orng Exit For End If Next End Sub |
|
| Tags |
| autocorrectnow |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Macro on Search and Replace | davidhuy | Word VBA | 1 | 12-19-2014 04:47 AM |
| Need Macro to Replace Text | rsrasc | Word VBA | 2 | 11-10-2014 06:26 PM |
| Windows 95 WordBasic (!!!) macro | NobodysPerfect | Word VBA | 4 | 08-25-2014 02:03 AM |
Find and Replace Macro
|
amparete13 | PowerPoint | 3 | 03-11-2014 05:29 AM |
Macro - replace with condition
|
ubns | Word VBA | 1 | 05-02-2012 12:52 AM |