Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-02-2024, 03:56 AM
hss001 hss001 is offline Read text from Start/End points Windows 10 Read text from Start/End points Office 2021
Novice
Read text from Start/End points
 
Join Date: Dec 2023
Posts: 20
hss001 is on a distinguished road
Default Read text from Start/End points

My requirement is for the user to save 2 points (start & end) in a Word document, and then for the system to loop through the sentences or paragraphs, and read and process each line.

BTW this will be controlled by Excel VBA but I think the code will be the same.

I can store the Start & End positions by using Selection.Range.
But, how would I loop through the sentences or paragraphs in-between.
I wasn't sure whether to use the Sentences or Paragraph objects.

Thanks

Last edited by hss001; 02-02-2024 at 03:56 AM. Reason: edit
Reply With Quote
  #2  
Old 02-02-2024, 06:26 AM
Italophile Italophile is online now Read text from Start/End points Windows 11 Read text from Start/End points Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Choose whichever meets your requirements. Processing paragraphs will be quicker and more accurate.
Reply With Quote
  #3  
Old 02-02-2024, 06:40 AM
hss001 hss001 is offline Read text from Start/End points Windows 10 Read text from Start/End points Office 2021
Novice
Read text from Start/End points
 
Join Date: Dec 2023
Posts: 20
hss001 is on a distinguished road
Default

How would I get the Document Paragraph numbers from the Selection.Range - start and end?
Reply With Quote
  #4  
Old 02-02-2024, 08:21 AM
Italophile Italophile is online now Read text from Start/End points Windows 11 Read text from Start/End points Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

What do you mean by "Document Paragraph numbers"?

If you want help it would be better to provide more detail of what you are trying to do.
Reply With Quote
  #5  
Old 02-05-2024, 02:44 AM
hss001 hss001 is offline Read text from Start/End points Windows 10 Read text from Start/End points Office 2021
Novice
Read text from Start/End points
 
Join Date: Dec 2023
Posts: 20
hss001 is on a distinguished road
Default

When I say "Document Paragraph numbers" I mean the ActiveDocument.Pararagraphs. I've used these previously in a solution I've written.

Here is what I want to achieve:
1. I have 2 Ranges with the Start and End point
2. I want to loop through all Paragraphs/Sentences between the Start and End Ranges

I'm unsure how to do this - some help or code samples would be greatly appreciated.
Reply With Quote
  #6  
Old 02-05-2024, 04:11 AM
Italophile Italophile is online now Read text from Start/End points Windows 11 Read text from Start/End points Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

If you are using Selection.Range you have one range, not two. A Range has a collection of paragraphs, as you would see by using the Object Browser, so you simply need to loop through them. For example:

Code:
    Dim rng As Range: Set rng = Selection.Range
    Dim para As Paragraph
    For Each para In rng.Paragraphs
        'do something
    Next para
Reply With Quote
  #7  
Old 02-05-2024, 04:19 AM
hss001 hss001 is offline Read text from Start/End points Windows 10 Read text from Start/End points Office 2021
Novice
Read text from Start/End points
 
Join Date: Dec 2023
Posts: 20
hss001 is on a distinguished road
Default

Ah right - I wasn't aware that a Range had a Paragraphs collection.

If I have 2 Ranges - start & end, how would I create another Range - which is the text between them?
Reply With Quote
  #8  
Old 02-05-2024, 04:37 AM
Italophile Italophile is online now Read text from Start/End points Windows 11 Read text from Start/End points Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

If you are using the current selection you do not have two ranges. You have one Range with a Start point and an End point. Range.Text is the text between them.

If you are separately obtaining the start and end point by some other means then you could use
Code:
Set rng3 = ActiveDocument.Range(Start:=rng1.Start, End:=rng2.End)
You may find it helpful to review the documentation:
Working with Range Objects | Microsoft Learn
Range object (Word) | Microsoft Learn
Reply With Quote
  #9  
Old 02-05-2024, 04:53 AM
hss001 hss001 is offline Read text from Start/End points Windows 10 Read text from Start/End points Office 2021
Novice
Read text from Start/End points
 
Join Date: Dec 2023
Posts: 20
hss001 is on a distinguished road
Default

Thanks Italophile - you've been great in helping me with this.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Read text from Start/End points Using bulltet points in Table changes position of the text DEQHUQBG Word 5 06-29-2020 03:32 AM
hide edit points of text/shape box Jackie Word 5 09-06-2015 04:23 PM
Read text from Start/End points Bullet Points in text boxes caz46 PowerPoint 2 11-17-2013 06:18 AM
Read text from Start/End points Bullet points with text? jjmclell Word 2 03-01-2013 11:42 AM
Edit Points in Curve: MS Office changes points properties itself, without my action. Sergey SPb PowerPoint 0 08-27-2012 05:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:36 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