How to get currently selected text in powerpoint 2008

Could some kind soul please explain to me how I can get the currently selected text in an applescript with powerpoint 2008 (version 12.1.5).

I'm assuming that the user has actually selected some text and, of course, powerpoint shows the normal view.

It must be possible (according to http://www.officeformac.com/blog/filter/category.powerpoint?@526.YOEBaibGJ53@ ) , but I can't find any examples anywhere. (And I am an applescript newbie.)

(I want to change some attributes of that selected text.)

All kinds of hints, pointers, examples, suggestions will be highly appreciated.

Thanks a lot in advance.

Best regards,
Gabriel.

Message was edited by: GabrielZ

MacBook Pro, Mac OS X (10.5.6), iPhone 2G w/ 2.1 FW, iTunes 8.0.1

Posted on Feb 5, 2009 6:27 AM

Reply
7 replies

Feb 10, 2009 11:22 AM in response to ericmeyers

Thanks a lot for the hint ... could you pleeease also give me a hint, how a "sentence" in applescript containing that selection object might look like?

For instance, I have no clue how to obtain the currently active shape (i suppose that object is what i need in order to get hold of the selected text ...)

As I said, I'm a newbie regarding applescript 😉

Thanks a lot in advance.

Best regards,
Gabriel.

Message was edited by: GabrielZ

Feb 10, 2009 12:06 PM in response to ericmeyers

I experimented a little and now I seem to be stuck at the following point:

tell application "Microsoft PowerPoint"      activate -- bring it to the front      --launch -- just launch it, if it is not yet running, but it stays in the background            set theSelection to selection of active window      set theSelType to selection type of theSelection      display dialog (theSelType as string)            if theSelType is text then             -- should be ' .. is selection type text' ?           display dialog "text"      end if end tell


Now, when I select some text and run the script, I get the text "selection type text" in the dialog box.
And when I select a text box, for instance, and run the script, then I get the output "selection type shapes".
Fine.

However, I don't know what to write in the line 'if theSelType is enum then'!
If I write 'selection type text' in place of enum, then the script editor won't save it.
If I write 'text' (as shown in the code above), then it does save it, but the body of the if is never executed.

Clueless ...

Best regards,
Gabriel.

Feb 11, 2009 12:31 AM in response to GabrielZ

Hello Gabriel,

Perhaps something like the code below may return the text in selection.
Wild guess based on the dictionary. Not tested.

--CODE1
tell application "Microsoft PowerPoint" -- PPT 2008
tell active window
set t to content of text range of selection
end tell
end tell
return t
--END OF CODE1

As for the said constant name (enumeration), run the following code and check the result window.
Whatever returned there should be the constant to be used in your script.

--CODE2
tell application "Microsoft PowerPoint" -- PPT 2008
tell active window
return get selection type of selection
end tell
end tell
--END OF CODE2

Good luck,
H

Feb 11, 2009 3:10 AM in response to Hiroto

Thanks a lot for your response.

Thanks to your response, I tried it again, and today it's working!
(I could've sworn that yesterday I tried it exactly the same way! ...)

Anyway, for the record, here is the complete script:
(is there any proper way to format code here? perhaps by a tag?)

-------- code

tell application "Microsoft PowerPoint"
activate -- bring it to the front

set theSelection to selection of active window
set theSelType to selection type of theSelection

if theSelType is selection type text then
-- only change font attribute if user has selected text;
-- not, if he has selected something else (shape, slide, etc.)

set theTextRange to text range of theSelection
-- display dialog (get font name of font of theTextRange)
-- display dialog ( (content of theTextRange) as string)

tell font of theTextRange
set fontSize to get font size
if fontSize ≥ 18 then
set fontSize to fontSize + 4
else
set fontSize to fontSize + 2
end if

set {font size, subscript, base line offset} to ¬
{fontSize, true, -0.15}
end tell

else
if theSelType is selection type none then set seltype to "none"
if theSelType is selection type slides then set seltype to "slides"
if theSelType is selection type shapes then set seltype to "shapes"
display dialog "No text selected (you selected " & seltype & ")" buttons {"Oh well .."} default button 1
end if

end tell
-------- code

This code works with powerpoint 2008, version 12.1.5.

Best regards,
Gabriel.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to get currently selected text in powerpoint 2008

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.