View Single Post
 
Old 09-12-2019, 12:20 AM
Genericname1111 Genericname1111 is offline Windows 7 64bit Office 97-2003
Novice
 
Join Date: Aug 2019
Posts: 17
Genericname1111 is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
Assuming by 'line' you mean 'paragraph' then

Code:
Sub Macro1()
Dim oPara As Paragraph
Dim oRng As Range
Dim intPos As Integer
    For Each oPara In ActiveDocument.Paragraphs
        Set oRng = oPara.Range
        oRng.End = oRng.End - 1 'omit the paragraph break from the range
        If UBound(Split(oRng.Text, Chr(9))) = 2 Then 'ensure there are two tab characters
            intPos = InStrRev(oRng.Text, Chr(9)) 'Find the second tab character position
            oRng.Start = oRng.Start + intPos '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 paragrapj
        End If
    Next oPara
    Set oPara = Nothing
    Set oRng = Nothing
End Sub
Hi, thanks for posting that. I'm getting "sub or function not defined" when I run it. I just copied it into a new macro to test it, is there something more I should have done?
Reply With Quote