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?
 
I'm not sure why you needed to remove the keyword "Set". Maybe you've changed your code somehow. If you post your code, I'll have a quick look.

For the slide name and ID, I think you'll need to use VBA. The following code will display in a message box with the slide ID and name for the slides in the active presentation.

Code:
[FONT=Courier New][COLOR=darkblue]Sub[/COLOR] DisplayIDsAndNames()

    [COLOR=darkblue]Dim[/COLOR] ppApp [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Object[/COLOR]
    [COLOR=darkblue]Dim[/COLOR] ppPres [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Object[/COLOR]
    [COLOR=darkblue]Dim[/COLOR] ppSlide [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Object[/COLOR]
    [COLOR=darkblue]Dim[/COLOR] sText [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]


    [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]Resume[/COLOR] [COLOR=darkblue]Next[/COLOR]
    [COLOR=darkblue]Set[/COLOR] ppApp = GetObject(, "PowerPoint.Application")
    [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]GoTo[/COLOR] 0
    
    [COLOR=darkblue]If[/COLOR] ppApp [COLOR=darkblue]Is[/COLOR] [COLOR=darkblue]Nothing[/COLOR] [COLOR=darkblue]Then[/COLOR]
        MsgBox "No PowerPoint presentation found.", vbInformation
        [COLOR=darkblue]Exit[/COLOR] [COLOR=darkblue]Sub[/COLOR]
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]


    [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]Resume[/COLOR] [COLOR=darkblue]Next[/COLOR]
    [COLOR=darkblue]Set[/COLOR] ppPres = ppApp.ActivePresentation
    [COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]GoTo[/COLOR] 0
    
    [COLOR=darkblue]If[/COLOR] ppPres [COLOR=darkblue]Is[/COLOR] [COLOR=darkblue]Nothing[/COLOR] [COLOR=darkblue]Then[/COLOR]
        MsgBox "No presentation found.", vbInformation
        [COLOR=darkblue]Exit[/COLOR] [COLOR=darkblue]Sub[/COLOR]
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    
    [COLOR=darkblue]If[/COLOR] ppPres.Slides.Count = 0 [COLOR=darkblue]Then[/COLOR]
        MsgBox "No slides found.", vbInformation
        [COLOR=darkblue]Exit[/COLOR] [COLOR=darkblue]Sub[/COLOR]
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]


    sText = "Index No" & vbTab & vbTab & "Slide Name" & vbCrLf
    sText = sText & "---------------------------------------" & vbCrLf
    
    [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] ppSlide [COLOR=darkblue]In[/COLOR] ppPres.Slides
        sText = sText & ppSlide.SlideIndex & vbTab & vbTab & ppSlide.Name & vbCrLf
    [COLOR=darkblue]Next[/COLOR] ppSlide
    
    MsgBox sText, vbInformation
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR][/FONT]
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Here is code:
Code:
Sub CopyToPPoint()



        Dim newPowerPoint As PowerPoint.Application
        Dim activeSlide As PowerPoint.Slide
        Dim PPPres As PowerPoint.Presentation
     
     '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
        
    Worksheets("3").Range("A1:N30").CopyPicture Appearance:=xlScreen, Format:=xlBitmap
        PPPres.Slides(3).Shapes.Paste  'and repeating these 2 lines on more slides/sheets


        
    AppActivate ("Microsoft PowerPoint")
    Set activeSlide = Nothing
    Set newPowerPoint = Nothing
    Set PPPres = Nothing
     
End Sub


Used on more sheets/slides and works well, only will try set the placement of table(pic) onto sheet.
Tommorow will try your code, when i have access to my work ntb (again).
 
Upvote 0
Oh I see. Instead of assigning the slide to a variable, you refer to the slide directly. Yeah, that will work too. :cool:
 
Upvote 0
Yeah and for this specific case i do not need the variables, seems. By the way, the code for SlideNames works perfect.

Thank you a lot for your help man! :)
 
Upvote 0

Forum statistics

Threads
1,215,049
Messages
6,122,864
Members
449,097
Latest member
dbomb1414

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
Back
Top