Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-15-2015, 07:03 AM
BobSundquist BobSundquist is offline How to replace WordBasic.AutoCorrectNow in an old macro? Windows 7 64bit How to replace WordBasic.AutoCorrectNow in an old macro? Office 2013
Novice
How to replace WordBasic.AutoCorrectNow in an old macro?
 
Join Date: Dec 2015
Posts: 2
BobSundquist is on a distinguished road
Default How to replace WordBasic.AutoCorrectNow in an old macro?

I am importing some old Word macros for use in Word 2013. One of them has the statement:
WordBasic.AutoCorrectNow
which is no longer recognized in Visual Basic. This statement would evaluate the word to the left of the cursor position and if it matched an autocorrect template would do the autocorrection. How can I do Autocorrect in New Visual Basic?
Reply With Quote
  #2  
Old 12-15-2015, 08:02 AM
gmayor's Avatar
gmayor gmayor is offline How to replace WordBasic.AutoCorrectNow in an old macro? Windows 10 How to replace WordBasic.AutoCorrectNow in an old macro? Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 12-16-2015, 02:32 PM
BobSundquist BobSundquist is offline How to replace WordBasic.AutoCorrectNow in an old macro? Windows 7 64bit How to replace WordBasic.AutoCorrectNow in an old macro? Office 2013
Novice
How to replace WordBasic.AutoCorrectNow in an old macro?
 
Join Date: Dec 2015
Posts: 2
BobSundquist is on a distinguished road
Default AutoCorrectNow

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
Reply With Quote
  #4  
Old 12-16-2015, 04:19 PM
Charles Kenyon Charles Kenyon is offline How to replace WordBasic.AutoCorrectNow in an old macro? Windows 8 How to replace WordBasic.AutoCorrectNow in an old macro? Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,082
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

I had to add the following statement at the beginning.
Dim Entry as Object

Word 2010
Reply With Quote
  #5  
Old 06-10-2022, 04:27 PM
Charles Kenyon Charles Kenyon is offline How to replace WordBasic.AutoCorrectNow in an old macro? Windows 10 How to replace WordBasic.AutoCorrectNow in an old macro? Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,082
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, 5 views)
Reply With Quote
  #6  
Old 06-11-2022, 07:19 PM
Charles Kenyon Charles Kenyon is offline How to replace WordBasic.AutoCorrectNow in an old macro? Windows 10 How to replace WordBasic.AutoCorrectNow in an old macro? Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,082
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

Here is one that handles more including multi-word AC entries. It is slow but may be worth using.
Code:
  Sub AutoCorrectBruteReplace2()
      ' https://answers.microsoft.com/en-us/msoffice/forum/all/macro-for-autocorrect/91f9bdb1-47ac-4cec-9842-5f1ee38bd7cf?page=1
      ' rianvillareal 2022-06-11 modified by Charles Kenyon with help by Hans Vogelar to use range and work with selected text
      ' It is slow. Handles multi-word entries. Does not handle fractions
      ' If text is selected, it operates only on selected text
      '       If nothing selected, it operates on entire document
      '
      Dim oEntry As Word.AutoCorrectEntry
      Dim oRng   As range
      Set oRng = Selection.range
      For Each oEntry In AutoCorrect.Entries
          With oRng.Find
              .ClearFormatting
              .Replacement.ClearFormatting
              .Text = oEntry.Name
              .Replacement.Text = oEntry.Value
              .Forward = True
              .Wrap = wdFindStop
              .Format = False
              .MatchCase = False
              .MatchWholeWord = True
              .MatchWildcards = False
              .MatchSoundsLike = False
              .MatchAllWordForms = False
              .Execute Replace:=wdReplaceAll
          End With
      Next
  End Sub
Reply With Quote
Reply

Tags
autocorrectnow

Thread Tools
Display Modes


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
How to replace WordBasic.AutoCorrectNow in an old macro? Find and Replace Macro amparete13 PowerPoint 3 03-11-2014 05:29 AM
How to replace WordBasic.AutoCorrectNow in an old macro? Macro - replace with condition ubns Word VBA 1 05-02-2012 12:52 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:50 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft