简体   繁体   中英

Is there any way to get call back from powerpoint, when any presentation opens? (Powerpoint 2016- Mac version)

I need to open my OS X application when any powerpoint presentation opens. I got VBA call back when powerpoint open (Auto_Open()). But I need a call back for each presentation open.

In windows we can open each presentation in separate powerpoint app (difference instance). In Mac , Powerpoint app will open once and all presentation will open under same powerpoint application (Powerpoint 2016- Mac version) .

I need a call back when each presentation file open and I need to do run code snippets in my cocoa application.

An idea of possible work around is to loop checking the presentations opened, and compare it with presentations already open before.

First, when this script starts running, it checks if PowerPoint is running (-> if not then quit). If PP runs, then the script records the number of open presentations.

Then script goes through a loop : in this example, it repeats 100 times (just for my test, but it should be repeat for ever !). For each iteration, it looks for list of PP presentation and compares with list before: if a presentation is not in previous list, then it is new, jut open !

The script also stops when you quit PowerPoint showing an alert (bloc try).

tell application "System Events" to set PP_Running to exists (processes where name is "Microsoft PowerPoint")
if not PP_Running then return -- Power point is not launched !
tell application "Microsoft PowerPoint" to set Old_list to name of every presentation -- get initial list of open presentations

repeat with I from 1 to 100 -- for test, but it should be repeat with no limit

try
    tell application "Microsoft PowerPoint" to set New_list to name of every presentation
on error
    display alert "PowerPoint no longer launched"
    return -- quit the loop
end try
repeat with aDoc in New_list
    if not (Old_list contains aDoc) then -- new document has been opened !!
        set Old_list to New_list
        log "Open new document = " & aDoc -- do what ever you need to do !!
    end if
end repeat
delay 0.5
set I to I + 1
end repeat

Tested on El Capitain / PP 2011 : but I think there is nothing changed from PP 2011 to PP 2016 in the 'name of every presentation'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM