Monday, October 26, 2020

#1 2020-10-12 11:49:37 am

T_Rex
Member
From:: Minneapolis
Registered: 2005-03-16
Posts: 49
Website

Select a range of text in Microsoft Word

I am trying to replace some text in a Microsoft Word document within a specific paragraph.
How do I actually select the whole paragraph so I can replace the characters at the end of it?

I have no clue as I have seen this is not so simple.

Thanks!


T_Rex

Offline

 

#2 2020-10-12 01:02:16 pm

roosterboy
Member
Registered: 2010-04-19
Posts: 27

Re: Select a range of text in Microsoft Word

How are you selecting the paragraph where you want to make replacements?

Is it the paragraph where the current insertion point is located? What if the selection spans multiple paragraphs?

Or is it a specific paragraph within a document, perhaps identified by index or something?

Or is it a paragraph where particular text can be found?

Here's how to select entire paragraph of the current selection, including multiple paragraphs should the selection span more than one.

Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Microsoft Word"
   
   set firstPP to first paragraph of selection
   set lastPP to last paragraph of selection
   
   tell active document
       
       set ppRange to ¬
           create range start (start of content of text object of firstPP) ¬
               end (end of content of text object of lastPP)
       
       select ppRange
       
   end tell
   
end tell

Last edited by roosterboy (2020-10-12 01:02:44 pm)

Offline

 

#3 2020-10-12 01:21:07 pm

T_Rex
Member
From:: Minneapolis
Registered: 2005-03-16
Posts: 49
Website

Re: Select a range of text in Microsoft Word

Thanks roosterboy.

What you shared may get me started. But I would like to take the text of a whole paragraph where a particular text can be found and replace a few characters (page numbers in a TOC, basically).

So after getting the range of selected paragraphs, I would like to select specific paragraphs based on what their first words are then change the page numbers at the end of the paragraphs.

Essentially I need to get the whole paragraph text, not just the reference, into a container I can then manipulate and then place back in.


T_Rex

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)