Problem with Range of slide in PPT, where i need to copy in.

Martin1991

New Member
Joined
Nov 14, 2017
Messages
24
Hello,
I was trying to look up for this formula, but can´t specify correctly the way of slide in PPT presentation, where i need to copy in some informations from the sheets.

Code:
Sub CopyToPPoint()


        Dim newPowerPoint As PowerPoint.Application
        Dim activeSlide As PowerPoint.Slide
        Dim PPPres As PowerPoint.Presentation
        Dim cht As Excel.ChartObject
     
     'Look for existing instance
        On Error Resume Next
        Set newPowerPoint = GetObject(, "PowerPoint.Application")
        On Error GoTo 0
     
        If newPowerPoint Is Nothing Then
            Set newPowerPoint = New PowerPoint.Application
            newPowerPoint.Visible = True
            Set PPPres = newPowerPoint.Presentations.Open("D:\docs\just_practise_soon_to_delete\EU Weekly pending report 2017'Wxx.pptx")
        Else
            Set PPPres = newPowerPoint.ActivePresentation
        End If
        newPowerPoint.ActiveWindow.ViewType = ppViewSlide
        
    Rang3 = ActivePresentation.Slides.Range(Array("Slide3"))
    
PasteRng PPPres, 3, Range("Rang3")
        
    AppActivate ("Microsoft PowerPoint")
    Set activeSlide = Nothing
    Set newPowerPoint = Nothing
    Set PPPres = Nothing
     
End Sub
            
Sub PasteRng(Pres, SlideNo, Rng As Range)
Dim PPPres As PowerPoint.Presentation
Rng = Worksheets("3").Range("A1:N30")
SlideNo = PPSlide.SlideIndex("3")
    Rng.CopyPicture Appearance:=xlScreen, Format:=xlBitmap ' copy the range
    Pres.Application.ActiveWindow.View.GotoSlide SlideNo 'PPSlide.SlideIndex    ' activate the slide no
    Pres.Application.ActiveWindow.View.PasteSpecial ppPasteOLEObject, msoFalse ' paste using pastespecial method
End Sub

Debugger comes with "error 429 :ActiveX component can´t create and object" stopping at part Rang3 = ActivePresentation.Slides.Range(Array("Slide3")) , where i try to define path to slide. FYI I m new to vba and i think it will be easy for someone more advanced, but can´t find the right solution even on forums.
Please, could you help someone?
 

Some videos you may like

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,406
Since Rang3 is being assigned an object, a SlideRange object to be specific, you'll need to use the keyword Set...

Code:
[COLOR=#ff0000]Set[/COLOR] Rang3 = ActivePresentation.Slides.Range(Array("Slide3"))

Also, you can declare your variable as follows...

Code:
Dim Rang3 as SlideRange

Hope this helps!
 

Martin1991

New Member
Joined
Nov 14, 2017
Messages
24
Well, I tried it, both metods and combined aswell, but it doesn´t work. Still same kind of error as i specified in the first post.
 

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,406
You'll also need to qualify the reference to ActivePresentation...

Code:
Set [COLOR=#333333]Rang3 = [/COLOR][COLOR=#ff0000]newPowerPoint.[/COLOR][COLOR=#333333]ActivePresentation.Slides.Range(Array("Slide3"))[/COLOR]

Actually, since you've already assigned a presentation to your variable PPPres..

Code:
Set [COLOR=#333333]Rang3 = [/COLOR][COLOR=#ff0000]PPPres[/COLOR][COLOR=#333333].Slides.Range(Array("Slide3"))[/COLOR]
 

Martin1991

New Member
Joined
Nov 14, 2017
Messages
24

ADVERTISEMENT

I will try it tommorow, when i will have access to my work computer. But if i understand you right, do you mean
Code:
Set Rang3 = PPPres.Slides.Range(Array("SLide3"))
will work when it is qualified upper in condition? Or do I need use whole
Code:
newPowerPoint.ActivePresentation.Slides.Range(Array("Slide3"))
??
 

Martin1991

New Member
Joined
Nov 14, 2017
Messages
24
I have tryed your code, and it solved the part of setting the range (except the fact, i can´t find how to define Slide3 - it adviced me "perhaps you meant Slide560"), i tryed and came another error in this part:
Code:
Set Rang3 = PPPres.Slides.Range(Array("Slide560"))
PasteRng PPPres, 3, Range("Rang3")
with error 1004 Method Range of object "_Global" failed... Well, i would be really like to make this macro runs -- > really lot of time saved afterware, but i don´t want to annoy with this forever. :) I cannot even find in PPT developer, how i recognize the index of specific Slide. Are you in about solving this or should i try another site? It is kind of unusual as i see to make vba works with ppt, not many articles about it on web as i was looking for.
 

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,406

ADVERTISEMENT

It looks like you're trying to pass a PowerPoint SlideRange to your PasteRng sub. The problem is that your sub expects a Range object. Also, it looks like you're complicating things needlessly. Try the following instead...

Code:
    'Declare a variable for your slide
    Dim ppSlide As PowerPoint.Slide

    'Assign your slide to your variable
    Set ppSlide = PPPres.Slides("Slide3")
    
    'Copy the range
    Worksheets("3").Range("A1:N30").CopyPicture Appearance:=xlScreen, Format:=xlBitmap

    'Paste the range into your slide
    ppSlide.Shapes.Paste

    'Select your slide
    ppSlide.Select

Does this help?
 

Martin1991

New Member
Joined
Nov 14, 2017
Messages
24
Yeah, man. You were right. I was trying too coplicated way.
At least now, it rly copy and paste the range, which i need to, but still remains the problem with SlideNumber. It debugged with (doesnt know "SLide3" object, perhaps you meant Slide560). I tried that Slide560 and it pasted the Pic into the First Slide. So i tried to use Slide562, but it doesnt work like this. Any idea about the marking of slides? Can´t look it up in PPT.
To being sure the code doesn´t include any fails i m giving it whole here:
Code:
Sub CopyToPowerPoint() 
        Dim newPowerPoint As PowerPoint.Application
        Dim activeSlide As PowerPoint.Slide
        Dim PPPres As PowerPoint.Presentation
        Dim cht As Excel.ChartObject
        Dim ppSlide As PowerPoint.Slide
        
        On Error Resume Next
        Set newPowerPoint = GetObject(, "PowerPoint.Application")
        On Error GoTo 0
     
        If newPowerPoint Is Nothing Then
            Set newPowerPoint = New PowerPoint.Application
            newPowerPoint.Visible = True
            Set PPPres = newPowerPoint.Presentations.Open("D:\docs\just_practise_soon_to_delete\EU Weekly pending report 2017'Wxx.pptx")
        Else
            Set PPPres = newPowerPoint.ActivePresentation
        End If


        Set ppSlide = PPPres.Slides("Slide560") 'Here is the problem, Slide 3 does not work
        
        Worksheets("3").Range("A1:N30").CopyPicture Appearance:=xlScreen, Format:=xlBitmap
        ppSlide.Shapes.Paste
        ppSlide.Select
        
    Set activeSlide = Nothing
    Set newPowerPoint = Nothing
    Set PPPres = Nothing
     
End Sub
 

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,406
To refer to a slide by name...

Code:
    PPPres.Slides("Slide1").Shapes.Paste

To refer to a slide by index...

Code:
    PPPres.Slides(1).Shapes.Paste

To refer to a slide by ID...

Code:
    PPPres.Slides.FindBySlideID(256).Shapes.Paste

Does this help?
 

Martin1991

New Member
Joined
Nov 14, 2017
Messages
24
Yes.
When i deleted the "set" part and use Index method, it worked. Still don´t get, where i can find the names or ID of slides? If you know, please tell, but its just a small info plus.
At final, it works for more slides as i needed, so i can copy 50 slides and tables.

Thank you very much for your help!!!
 

Watch MrExcel Video

Forum statistics

Threads
1,122,569
Messages
5,596,918
Members
414,110
Latest member
docops

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top