PDA

View Full Version : copy ppt slide into new ppt via vba and button



banane78
12-24-2012, 10:58 AM
Hi,

I have loads of ppt slides in one ppt and I would like to use a button to copy the active slide into a new ppt which has to be created after pressing the button for the first time. Then the slide should move to the new ppt without the button on it - would be perfect.
Thanks a lot.

John Wilson
12-29-2012, 08:53 AM
Since a button will only work in SHOW mode I don't see why you would want to do that. The new presentation will open in edit mode in front of your show.

If you want this to work in edit mode you will need to write an AddIn. (Which I'm guessing might be a little more than you are ready for) or run the macro from the toolbar / ribbon / menu

banane78
12-29-2012, 01:33 PM
hi thanks for your reply.
Yes, the button should be used in the slide show modus.
The idea is to have one "slide library-with loads of slides" and you take out the desired slides by pushing the button and then they will appear in a new ppt..I have found the following code in another forum but it gives me an error.

Hope you can help.
Thanks a lot.

Code as button click:
Private Sub [Button Click]
CopySlideEx ActiveWindow.Selection.SlideRange.SlideIndex
End Sub

Code in module:
Public Sub CopySlideEx (intSlideNr As Integer)

Dim objPpPresi As Object
Dim strPath As String
Dim i as Integer


strPath = ""
If Dir(strPath) <> "" Then
Set objPpPresi = Application.Presentations.Add(True)
Else
Set objPpPresi = Application.Presentation.Open(strPath, msoTrue)
End If

'copy action
ActivePresentation.Slides.Range(intSlideNr).Copy
objPpPresi.Slides.Paste


With objPpPresi.Slides(objPpPresi.Slides.Count)
For i = .Shapes.Count to 1 Step -1
If .Shapes(i).Type = [ButtonControll-Ding] Then
msoFormControl
.Shapes(i).Delete
Exit For
End If
DoEvents
Next i
End With


objPpPresi.Save
objPpPresi.Close
Set objPpPresi = Nothing

End Sub

[I]ERROR Says:
Global unkown member: Invalid Request:
There is no currently active document window.

John Wilson
12-30-2012, 03:07 AM
There is no active window in show mode and it's impossible to have a selection so the code you have can never work.

You would need to use SlideShowWindows(1) instead.

You can reference the active slide like this:

SlideShowWindows(1).View.Slide

To be honest this is something you should do in edit mode using an addin though.

banane78
12-30-2012, 06:13 AM
Thanks a lot for ur support.
Unfortunately, it has to work in the slide show modus.

I tried to change the code as following:

Private Sub CommandButton1_Click()
CopySlideEx SlideShowWindows(1).View.Slide.SlideIndex
End Sub

But since it doesnt work I think I have done something wrong.
THe other thing I asked myself is cant I reference to single slides with number I mean I paste the code above to all slides so I could reference the slide directly? Is this a way to solve the problem?

I can send you my ppt file so you can have a look why I need to run it in show modus.

Again, thanks a lot for your support.

John Wilson
12-30-2012, 09:40 AM
I would definitely NOT recommend doing this in show mode and to be honest the code you have found doesn't make a lot of sense.

Try this instead (still not recommended)

Put the button on the Slide MASTER and make it run this code

Option Explicit
Public otarget As Presentation
Private Sub CommandButton1_Click()
Dim osource As Presentation
Dim currPos As Long
Set osource = SlideShowWindows(1).Parent
Application.WindowState = ppWindowMinimized
currPos = SlideShowWindows(1).View.Slide.SlideIndex
Err.Clear
On Error Resume Next
Debug.Print otarget.Name
If Err <> 0 Then Set otarget = Application.Presentations.Add
otarget.Slides.InsertFromFile osource.FullName, otarget.Slides.Count, currPos, currPos
End Sub

NOTE you are adding slides from the SAVED version so make sure it has bben saved recently!

banane78
12-30-2012, 12:02 PM
Many thanks! After more than a week I am close to what I want :)
Well, I have attached my ppt just to show u my idea.

This is what I try
First. the ppt will open only in show mode - and only the library slide can be accessed.
Then u would get to the slide library on which numerous slides (as picture) well show up and u can click on each slide and get to the full slide via hyperlink then on the full slide u can decide to take it (to new ppt) or go back to library and so on.

THe only thing I need now is that the code creates a new ppt slide only at the first time the button is pressed..all other slides should move to this new ppt.

Please find attached the ppt idea.
Thanks a lot for ur help u save my new year :rotlaugh:

banane78
01-01-2013, 06:35 AM
hi hope you can help me again.

I want to specify the ppt where all slides should be pasted in.

Can you help me to create a button saying or better automatically with opening the ppt including the code above, Open ppt "name XY"
and then paste the selected slides in that "name XY" presentation one after the other.

Thanks a lot.

John Wilson
01-01-2013, 09:30 AM
Change this line:
If Err <> 0 Then Set otarget = Application.Presentations.Add

To
If Err <> 0 Then Set otarget = Presentations.Open("full path to file here")

banane78
01-01-2013, 09:41 AM
Thank you very much John. That works.
Last question I hope, how can I change that the subsequent selected slides are pasted only in that ppt one after other?

Thanks a alot for your support.

banane78
01-02-2013, 04:27 PM
Hi John

Thanks I understood now, I have copied the button in master slide. It works perfectly. Thanks a lot.

Just two things:
THe slides are now copied with the button and a hyperlink saying "BACK". Can you please modify the code that the copied slides do not contain the button and the hyperlink/ word "BACK"?

+ How can I create a button in ppt that automatically opens the save to menue?

Thanks a lot for your support.

Johncoltrane
01-29-2013, 02:47 AM
Hi guys,
Thanks for giving such a useful information. This would help to other people also, who work in PowerPoint. PowerPoint has many shortcuts, so It enhances work speed ans saves your time. http://powerpointpresentation.blinkweb.com/1/2013/01/improving-your-powerpoint-presentations-using-shortcut-keys-4e857/

John Wilson
01-29-2013, 05:53 AM
So that's why you've been posting nonsense. You're a spammer.