View Single Post
 
Old 06-19-2025, 05:54 AM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Quote:
Originally Posted by Chopper View Post
I have a bunch of text (MS Word - hundreds of pages) that contains LOTS of instances of two adjacent words run together, i.e., the space between them has been omitted (this is OCR text and apparently the product of a rather crappy OCR program). Anyway, i am trying to correct as many of these "glued together pairs' as I can using a programmatic approach. Specifically, I would like to be able to find and select these pairs by searching and selecting them based on Word's ability to "mark" misspellings with the infamous "wavy red line" (WRL). Problem is, I haven't so far been able to discover whatever mysterious magic Microsoft uses to instigate displaying the WRL.

Many MS gurus just tell me it is not possible, but that makes no sense to me; my computer is responding to some sort of stimulus to display the WRL on the screen when a misspelled word is encountered, so it must be marked in some way. Ideas?

I will sort out how to figure the proper place to place the needed space once I am able to find/select the the "glued pair". Any help/comments/information anyone can offer will be muchly appreciated.


As Paul has already provens, your so called MS gurus are incorrect. Here is an adaptation of code Paul referred you to. It is up to you to decide if you want to define joined and split pairs for processing:



Code:
Sub AutoSpellCorrect()
Dim oDic As Object
Dim oRng As Range, oSuggestions As Variant
Dim arrJoined() As String, arrSplit() As String
Dim lngIndex As Long
  'Here I have defined a short list of Joined/Split word pairs. You could also use an exteranl list e.g., Excel or word table.
  arrJoined = Split("currentedition|happyending|towncounsel", "|")
  arrSplit = Split("current edition|happy ending|town counsel", "|")
  Set oDic = CreateObject("Scripting.Dictionary")
  For lngIndex = 0 To UBound(arrJoined)
    oDic.Add arrJoined(lngIndex), arrSplit(lngIndex)
  Next lngIndex
  For Each oRng In ActiveDocument.Range.SpellingErrors
    With oRng
      If oDic.Exists(oRng.Text) Then
        oRng.Text = oDic(oRng.Text)
      Else
        oRng.Select
        If .GetSpellingSuggestions.Count > 0 Then
          Set oSuggestions = .GetSpellingSuggestions
          oRng.Text = InputBox("Replace this spelling error with ... ", "REPLACEMENT", oSuggestions(1))
        Else
          oRng.Text = InputBox("Replace this spelling error with ... ", "REPLACEMENT", oRng.Text)
        End If
      End If
    End With
  Next
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote