View Single Post
 
Old 09-15-2019, 08:13 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 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

Is this code being run on a laptop or a PC that is normally hibernated rather than switched off? If so reboot the PC and try the code again. If not try the following which approaches the task from another direction
Code:
Sub Macro1()
Dim oPara As Paragraph
Dim oRng As Range
    For Each oPara In ActiveDocument.Paragraphs
        Set oRng = oPara.Range
        oRng.End = oRng.End - 1    'omit the paragraph break from the range
        If InStr(1, oRng.Text, Chr(9)) > 0 Then
            oRng.Collapse 0
            oRng.MoveStartUntil Chr(9), wdBackward    'move the start of the range to that position
            MsgBox Trim(oRng.Text)    'this is the text in the paragraph. Trim to remove spurious spaces
            oRng.Collapse 1    'this is the start of the text portion of the paragraph
        End If
    Next oPara
    Set oPara = Nothing
    Set oRng = Nothing
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