Selecting multiple words via AppleScript in PowerPoint
I'm trying to come up with an AppleScript that selects multiple adjacent words in a Microsoft PowerPoint slide.
I figured out how to select single words, and how to select the entire range of a text shape, but I cannot figure out how to select a custom range of multiple adjacent words.
Apple Script for selecting a single word:
tell application "Microsoft PowerPoint"
tell active presentation
tell slide 1
repeat with j from 1 to count of shapes
set aShape to shape j
if (name of aShape is "Title 1") then
select word 2 of text range of text frame of aShape
end if
end repeat
end tell
end tell
end tell
Apple Script for selecting the complete text shape:
tell application "Microsoft PowerPoint"
tell active presentation
tell slide 1
repeat with j from 1 to count of shapes
set aShape to shape j
if (name of aShape is "Title 1") then
set myTextFrame to text frame of aShape
set myRange to text range of myTextFrame
select text range of myTextFrame
end if
end repeat
end tell
end tell
end tell
Solution 1:
You are very close. Let's say you want to select words 2 through 4 of your text frame of aShape:
Where you have this:
select word 2 of text range of text frame of aShape
change it to this:
select words 2 thru 4 of text range of text frame of aShape
You could put in any number you want in there, not just 4, of course. If you might need to specify a different ending word every time you run the script you could extend this script by displaying a dialog box and asking for input.