View Single Post
 
Old 09-15-2019, 11:55 PM
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
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
Thanks for that. After running that, it brings up the text from each line in dialogue boxes, but I think I explained what I wanted badly in my opening post, sorry. Basically I'm wanting to know how to use a macro to navigate to the start of the paragraph so that when running various macros that change/delete/add text I can alter body text without changing the Q and A text (since the Q and A lines have different amounts of text before the paragraph starts, so I can't use the home key).
Reply With Quote