#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
Choose whichever meets your requirements. Processing paragraphs will be quicker and more accurate.
|
#3
|
|||
|
|||
How would I get the Document Paragraph numbers from the Selection.Range - start and end?
|
#4
|
|||
|
|||
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. |
#5
|
|||
|
|||
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. |
#6
|
|||
|
|||
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 |
#7
|
|||
|
|||
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? |
#8
|
|||
|
|||
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) Working with Range Objects | Microsoft Learn Range object (Word) | Microsoft Learn |
#9
|
|||
|
|||
Thanks Italophile - you've been great in helping me with this.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 |
Bullet Points in text boxes | caz46 | PowerPoint | 2 | 11-17-2013 06:18 AM |
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 |