Sign in to follow this  
Followers 0
daudi

copy powerpoint slide

10 posts in this topic

#1 ·  Posted (edited)

Hi,

I would like to create an autoit script that copies from one presentation to another.

I'm using powerpoint.au3 and am trying do the following:

1) create a new presentation file and save it (new.pptx)

2) open an existing presentation (old.pptx)

3) navigate to the slide that I want in old.pptx

4) copy the slide

5) switch to new.pptx

6) paste the slide

Steps 4 (and therefore 6) don't work. It seems that the slide is not copied, so when the script switches to new.pptx it pastes whatever text was in the clipboard into the first slide in new.pptx.

powerpoint.au3 does not contain functions to copy and paste slides, so I'm trying to copy the slide with Send("^{c}").

Any ideas how I can do this?

Thanks.

Edited by daudi

Share this post


Link to post
Share on other sites



Are you using Ctrl+A to select all first? if possible, post your code.

Share this post


Link to post
Share on other sites

Are you using Ctrl+A to select all first? if possible, post your code.

Thanks. I don't want to select all slides, just specific slides (the idea is to create a script that can take a subset of slides from different powerpoint files and put them into one new presentation. Here's the code:

#include "PowerPoint.au3"
#include <misc.au3>

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
Global $objPPT = _PPT_PowerPointApp()

$PresInterface = _PPT_CreatePresentation($objPPT) ;Get presentation interface
Global $objPres = _PPT_PresentationAdd($PresInterface) ;Add a new presentation
_PPT_PresentationSaveAs($objPres, @ScriptDir & "\new.pptx")
$objSlide1 = _PPT_SlideCreate($objPres, 1, $PPLAYOUTTEXT)

; Open the presentation we are taking a slide from.
$objPPS = _PPT_PresentationOpen($objPPT, "old.pptx")


WinWaitActive("old.pptx")
Send("^{HOME}") ; Make sure we are on the first slide
Send("{DOWN 2}") ; Move to a specific slide
Send ("^{c}") ; Copy the slide

; Select the new presentation
WinActivate("new.pptx")
WinWaitActive("new.pptx")
Send ("^{v}") ; paste the slide

This moves to the correct slide in old.pptx so that part is working.

Share this post


Link to post
Share on other sites

Ok, when i try to do this manually, Using Home then down a couple times doesnt let me even copy the slide manually, but i added a couple more moves and it worked.

What you would need to do is continue like you did, but when you are ready to copy, Send Control+D to duplicate the current slide, this has the side effect of also selecting the slide properly so that you can copy and paste it.

Then just copy and paste like normal, making sure not to save the old presentation of course.

Let me know if this helps.

Share this post


Link to post
Share on other sites

This moves to the correct slide in old.pptx so that part is working.

Hi - Why not keep your script open until you copied all your slides and then close the script.

This will add your slides to the new .pptx. When you press the escape button close the old.pptx and stop the script.

To copy and paste while the script is running just push the "Home" key.

#include "PowerPoint.au3"
#include <misc.au3>
AutoItSetOption("WinTitleMatchMode", 2); To match part of a Title will have to experiment a little
HotKeySet("{ESC}", "Ontsnap"); Exit program <<<< =============
HotKeySet("{home}", "CopyPaste") ;Home button to copy and paste current slide <<<<< ==============
$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
Global $objPPT = _PPT_PowerPointApp()
$PresInterface = _PPT_CreatePresentation($objPPT) ;Get presentation interface
Global $objPres = _PPT_PresentationAdd($PresInterface) ;Add a new presentation
_PPT_PresentationSaveAs($objPres, "e:\temp\new.pptx"); New slide
Sleep(100)
$objSlide1 = _PPT_SlideCreate($objPres, 1, $PPLAYOUTTEXT)
; Open the presentation we are taking a slide from.
$objPPS = _PPT_PresentationOpen($objPPT, "e:\temp\test.pptx"); Old slide
Sleep(100)
WinWaitActive("test.pptx")
While 1; Keep program running until Esc button is used
    Sleep(13)
WEnd
Func Ontsnap()
    _PPT_PresentationClose($objPPS)
    Exit 0
EndFunc   ;==>Ontsnap
Func copypaste()
    $CurrentWindowTitle = WinGetTitle("[active]"); Get current window title to return to
    MsgBox(0, 'Current Window Title', $CurrentWindowTitle, 5)
    Send("^{c}") ; Copy the slide
    Sleep(100)
    While Not WinActive("new.pptx", ""); ensuring this window is active before going to the next step
        WinActivate("new.pptx", "")
        Sleep(100)
    WEnd
    Send("^{v}") ; paste the slide
    WinActivate("Test.pptx", "")
    WinWaitActive("Test.pptx", "")

EndFunc   ;==>copypaste

Share this post


Link to post
Share on other sites

Ok, when i try to do this manually, Using Home then down a couple times doesnt let me even copy the slide manually, but i added a couple more moves and it worked.

What you would need to do is continue like you did, but when you are ready to copy, Send Control+D to duplicate the current slide, this has the side effect of also selecting the slide properly so that you can copy and paste it.

Then just copy and paste like normal, making sure not to save the old presentation of course.

Let me know if this helps.

Thanks! That does it. Here's the working prototype:

#include "PowerPoint.au3"
#include <misc.au3>

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
$objPPT = _PPT_PowerPointApp()

$PresInterface = _PPT_CreatePresentation($objPPT) ; Get presentation interface
$objPres = _PPT_PresentationAdd($PresInterface) ; Add a new presentation
_PPT_PresentationSaveAs($objPres, @ScriptDir & "\new.pptx")
$objSlide1 = _PPT_SlideCreate($objPres, 1, $PPLAYOUTTEXT)


; Open the presentation we are taking a slide from.
$objPPS = _PPT_PresentationOpen($objPPT, "old.pptx")


WinWaitActive("old")
Send("^{HOME}") ; Make sure we are on the first slide
Send("{DOWN 2}") ; Move to a new slide
Send ("^{d}") ; Duplicate the slide (this also selects it)
Send ("^{c}") ; Copy the slide
Send ("^{z}") ; un-duplicate the slide

; Select the new presentation
WinActivate("new")
WinWaitActive("new")
Send ("^{v}") ; paste the slide

; Close the source presentation, which is unchanged.
_PPT_PresentationClose($objPPS)

I can add code that repeats the process for other slides from other presentations.

Thanks again!

Share this post


Link to post
Share on other sites

Hi - Why not keep your script open until you copied all your slides and then close the script.

This will add your slides to the new .pptx. When you press the escape button close the old.pptx and stop the script.

To copy and paste while the script is running just push the "Home" key.

[...]

Thanks. I'm new to autoit so I might be misreading your code, but I don't think this does what I need. I want to be able to select arbitrary slides from different presentations and put them into a new one. I have a database of slides and plan to generate the autoit script automatically, and then just run it to create the new presentation without any user involvement. It looks to me like your code requires the user to do something.

Share this post


Link to post
Share on other sites

OK, with the careful application of brute force and ignorance I have figured out that I can simplify things considerably using COM. I took me a little while to find the way to do this, but my code is now:

#include "PowerPoint.au3"
#include <misc.au3>

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$objPPT = _PPT_PowerPointApp()

$PresInterface = _PPT_CreatePresentation($objPPT) ; Get presentation interface
$objPres = _PPT_PresentationAdd($PresInterface) ; Add a new presentation
_PPT_PresentationSaveAs($objPres, @ScriptDir & "\new.pptx")

; Open the presentation we are taking a slide from.
$objPPS = _PPT_PresentationOpen($objPPT, "old.pptx")

$objPPS.Slides(2).Copy ; Copy slide number 2 from the old presentation
$objPres.Slides.Paste ; Paste into the new presentation

_PPT_PresentationClose($objPPS) ; Close the source (old) presentation

Share this post


Link to post
Share on other sites

Thanks. I'm new to autoit so I might be misreading your code, but I don't think this does what I need. I want to be able to select arbitrary slides from different presentations and put them into a new one. I have a database of slides and plan to generate the autoit script automatically, and then just run it to create the new presentation without any user involvement. It looks to me like your code requires the user to do something.

In an earlier post you said this:

Thanks. I don't want to select all slides, just specific slides (the idea is to create a script that can take a subset of slides from different powerpoint files and put them into one new presentation.

So with my script you can select just the one slide you want and it will paste that slide to your new presentation.


Share this post


Link to post
Share on other sites

#10 ·  Posted

[...]

So with my script you can select just the one slide you want and it will paste that slide to your new presentation.

Gotcha. I should have been clearer in my initial specification of what I was trying to do. Thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0