Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-15-2019, 08:13 PM
gmayor's Avatar
gmayor gmayor is offline Macro to navigate to specific point in line (Word 97) Windows 10 Macro to navigate to specific point in line (Word 97) Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
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 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
  #2  
Old 09-15-2019, 11:55 PM
Genericname1111 Genericname1111 is offline Macro to navigate to specific point in line (Word 97) Windows 7 64bit Macro to navigate to specific point in line (Word 97) Office 97-2003
Novice
Macro to navigate to specific point in line (Word 97)
 
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to navigate to specific point in line (Word 97) Excel Macro finding a specific word ducky831 Excel Programming 3 09-17-2015 01:36 PM
Macro to navigate to specific point in line (Word 97) Cannot scroll past specific point in doc sunriver Word 3 06-24-2015 07:00 PM
Macro to navigate to specific point in line (Word 97) macro to add brackets to each line and add single quotes to each word in the line bracketandquotes Word VBA 17 02-16-2015 03:51 PM
Macro to navigate to specific point in line (Word 97) Deleting A blank Line that has a specific heading style , word 2010 & 2013 SteveWcg Word 5 01-08-2014 10:37 PM
Macro to navigate to specific point in line (Word 97) Point to a specific cell ericerler Mail Merge 1 08-11-2011 05:31 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:46 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft