Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-05-2016, 05:58 PM
kirkm kirkm is offline Get next paragraph Windows XP Get next paragraph Office 2003
Advanced Beginner
Get next paragraph
 
Join Date: Aug 2013
Posts: 40
kirkm is on a distinguished road
Default Get next paragraph

Hi, I've never used VBA in Word but via Google fugured this..



Code:
Sub ShowPARA()
Dim p As Paragraph, pp As String
For Each p In ActiveDocument.Paragraphs
    pp = p.Range.Text
    If Val(pp) > 279 Then
        Debug.Print pp
        Stop
    End If
Next
End Sub
I want to show the next paragraph as well as pp.
This is to let me check the contents for any mistakes.
Reply With Quote
  #2  
Old 09-05-2016, 08:41 PM
gmayor's Avatar
gmayor gmayor is offline Get next paragraph Windows 10 Get next paragraph 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

I assume you only want to find the first instance?

Code:
Sub ShowPARA()
Dim p As Paragraph, pp As String
Dim pp2 As String
    For Each p In ActiveDocument.Paragraphs
        pp = p.Range.Text
        If Not p.Range.End = ActiveDocument.Range.End Then
            pp2 = p.Range.Next.Paragraphs(1).Range.Text
        Else: pp2 = ""
        End If
        If Val(pp) > 279 Then
Debug.Print pp & pp2 & vbCr
            Exit For    'stop processing the loop
        End If
    Next p
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
  #3  
Old 09-05-2016, 10:30 PM
kirkm kirkm is offline Get next paragraph Windows XP Get next paragraph Office 2003
Advanced Beginner
Get next paragraph
 
Join Date: Aug 2013
Posts: 40
kirkm is on a distinguished road
Default

Thanks Graham. It's every instance but just the first will do and I should be able to nut something out from that.
Would you have an example to add some text into the paragraph?
Thanks.
Reply With Quote
  #4  
Old 09-05-2016, 11:34 PM
gmayor's Avatar
gmayor gmayor is offline Get next paragraph Windows 10 Get next paragraph 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

The following will insert text before and after the paragraph (lose the line you don't want)

Code:
Sub ShowPARA()
Dim p As Paragraph, pp As String
Dim pp2 As String
Dim oRng As Range
    For Each p In ActiveDocument.Paragraphs
        Set oRng = p.Range
        oRng.End = oRng.End - 1
        If IsNumeric(oRng.Text) Then
            pp = oRng.Text
            If Not oRng.End = ActiveDocument.Range.End Then
                pp2 = oRng.Next.Paragraphs(1).Range.Text
            Else: pp2 = ""
            End If
            If val(pp) > 279 Then
                oRng.InsertAfter " Text to insert"
                oRng.InsertBefore "Text to insert "
                oRng.End = p.Range.End
                pp = oRng.Text
Debug.Print pp & pp2
            End If
        End If
    Next p
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
  #5  
Old 09-06-2016, 01:29 AM
kirkm kirkm is offline Get next paragraph Windows XP Get next paragraph Office 2003
Advanced Beginner
Get next paragraph
 
Join Date: Aug 2013
Posts: 40
kirkm is on a distinguished road
Default

Cool.. that will get me started nicely.
Thanks you
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Get next paragraph compare each paragraph with the preceding paragraph cyraxote Word VBA 6 10-09-2015 08:03 AM
Replacing paragraph formatting before column break also changes the next paragraph after the break jjmartin1340 Word 3 09-21-2015 10:50 PM
Get next paragraph Narrow Paragraph to Wide Paragraph HELP icloudy Word 1 12-09-2012 03:49 PM
spacing within paragraph psmoore Word 1 06-22-2010 02:15 AM
Paragraph cloa513 Word 1 12-29-2009 02:20 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:47 AM.


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