Consulting

Results 1 to 18 of 18

Thread: Remove surplus spaces

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Mar 2020
    Posts
    79
    Location

    Remove surplus spaces

    I have a macro as per the attached .docm containing also the sample text.
    It removes improper returns that have been left by OCRing documents. I am ok with the macro as is except the excess spaces. In the example it asks you to confirm the action on the 3 places highlighted. When complete you will notice that there are in some cases excess spaces between the two highlighted words. Is it possible to deal with these as part of the macro? I have made the macro to focus on just replacing the Chr(13), so that you don't get format bleed that would normally happen on a search and replace.

    Public Sub FixOCR_Returns_Click()
    Dim oRng       As Range
    Set oRng = ActiveDocument.Content
    Set oRng = Selection.Range
    
    
    Selection.Find.ClearFormatting
    With oRng.Find
        .Text = "([A-Z0-9a-z\-,’;:'\) " & ChrW(880) & "-" & ChrW(8190) & _
                "]{1,3})^13([ A-Za-z'""""0-9‘(" & ChrW(880) & "-" & ChrW(8190) & "]{1,2})"
    
    
        .MatchWildcards = True
        .Font.Superscript = False
    
    
        Do While .Execute
            oRng.Select
            'Call SelectionScrollIntoMiddleOfView
            Select Case MsgBox("Replace " & oRng & "?", vbYesNoCancel)
    
    
                Case vbYes:
                    oRng.MoveEndUntil Chr(13), wdBackward
                    oRng.MoveStartWhile Chr(13)
                    oRng.MoveStartUntil Chr(13)
                    oRng.Select
                    oRng.Text = Replace(oRng.Text, Chr(13), " ")
    
    
                    oRng.Collapse wdCollapseEnd
                Case vbNo:
                    oRng.Collapse wdCollapseEnd
                Case Else
                    Selection.Collapse wdCollapseStart
                    Exit Sub
            End Select
    
    
        Loop
        MsgBox ("No more matches found")
    End With
    lbl_Exit:
    Exit Sub
    
    
    End Sub
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •