View Single Post
 
Old 06-10-2022, 04:27 PM
Charles Kenyon Charles Kenyon is offline Windows 10 Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,530
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

When I run this, it seems to require selecting the text that should trigger AutoCorrect and then running the macro for that term. It does not work if I select a block of text and run it. Here is one that Hans Vogelar tweaked for me based on it. It is not perfect but covers everything in the attached sample document.
Code:
  Sub AutoCorrectNow2()
      ' Graham Mayor Bob Sundquist, Hans Vogelar and Charles Kenyon 2022-06-10
      ' https://eileenslounge.com/viewtopic.php?f=26&t=38297&p=296123#p296123
      ' https://www.msofficeforums.com/word-vba/29148-how-replace-wordbasic-autocorrectnow-old-macro.html
      ' Runs autocorrect on selected text as if it were being retyped
      '
      '
      Dim oWrd   As range
      Dim Entry  As Object
      Dim iCount As Long, i As Long
      On Error Resume Next
      Let iCount = Selection.Words.Count
      For i = 1 To iCount
          Set oWrd = Selection.Words(i)
          For Each Entry In Word.Application.AutoCorrect.Entries
              If oWrd.Text = Entry.Name Then
                  oWrd.Text = Entry.Value
                  Exit For
              ElseIf oWrd.Text = Entry.Name & " " Then
                  oWrd.Text = Entry.Value & " "
                  Exit For
              End If
          Next Entry
      Next i
      Set oWrd = Nothing
      Set Entry = Nothing
   End Sub

This will only handle single-word entries.
Attached Files
File Type: docx deleteme AutoCorrectNow Macro.docx (20.3 KB, 7 views)
Reply With Quote