Results 1 to 20 of 71

Thread: Copy each excel worksheets and paste in each indivual slides

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #28
    VBAX Regular
    Joined
    Mar 2016
    Posts
    47
    Location
    I came up with the following script:

    Sub ChartToPresentation()
             
    Dim ppApp As PowerPoint.Application
    Dim ppPres As PowerPoint.Presentation
    Dim ppSlide As PowerPoint.Slide
    Dim shp As String
    Dim newShape As PowerPoint.ShapeRange
    Dim cell As Range
    Dim rng As Range
    Dim RangeName As String
    Dim CellName As String
    ' Make sure a chart is selected
    If ActiveChart Is Nothing Then
        MsgBox "Please select a chart and try again.", vbExclamation, _
            "No Chart Selected"
    Else
        ' Reference existing instance of PowerPoint
        Set ppApp = GetObject(, "Powerpoint.Application")
        ' Reference active presentation
        Set ppPres = ppApp.ActivePresentation
        ' Reference active slide
        RangeName = "PPTSlide"
        CellName = "B6"
        
        Set cell = Worksheets("VIVA GRAPH").Range(CellName)
        Worksheets("VIVA GRAPH").Names.Add Name:=RangeName, RefersTo:=cell
                      
        ' Copy chart as a picture
        ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, _
            Format:=xlPicture
        ' Paste chart
        Set newShape = ppSlide.Shapes.Paste
    With newShape
        .IncrementLeft 400
        .IncrementTop 250
        .ScaleWidth 0.87, msoFalse, msoScaleFromTopLeft
        .ScaleHeight 0.87, msoFalse, msoScaleFromTopLeft
    End With
        ' Clean up
        Set ppSlide = Nothing
        Set ppPres = Nothing
        Set ppApp = Nothing
    End If
    End Sub
    I am referring to the sheet "VIVA GRAPH" and made a range (via Name Manager) called "PPTSlide" that is linked to cell B6. However, it gives "Object variable or With block variable not set" at this piece of code: Set newShape = ppSlide.Shapes.Paste.

    What am I missing?

    Yours sincerely,

    Djani
    Last edited by Djani; 03-22-2016 at 05:50 AM. Reason: missing information

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •