Excel to PowerPoint vba Oddities

ddmx

New Member
Joined
Sep 26, 2011
Messages
2
Hello,

Below is my code. It takes a range with a few charts in excel, copies it, and pastes it into powerpoint starting with the 2nd slide (first and last are predefined header slides). If you run this code straight through, it gives an error on

"ShapeRange (unknown member) : Invalid Request. To select a shape, its view must be active"
Code:
pptSlide.Shapes.PasteSpecial(DataType:=ppPasteBitmap).Select

Excel somehow has already pasted the shape onto slide 2 at this point, yet has failed to select slide 2 in the active powerpoint presentation.

If I step through the code one step at a time, there are no errors given and it works as needed. Only when running it does it produce this error. Any help would be much appreciated. Thanks.

Code:
Sub exportPP1()
Dim pptApp As PowerPoint.Application
Dim pptPres As PowerPoint.Presentation
Dim pptSlide As PowerPoint.Slide
Dim LTSheets As Integer
Dim LTPath As String
Dim LTBook As String
Dim LTTemp As String
Dim i As Integer
LTSheets = Application.Sheets.Count
LTPath = ActiveWorkbook.Path
LTBook = ActiveWorkbook.Name
If pptApp Is Nothing Then Set pptApp = New PowerPoint.Application
pptApp.Visible = True
pptApp.Presentations.Open FileName:=LTPath & "\LT_Temp.ppt"
Set pptPres = pptApp.ActivePresentation
LTTemp = pptPres.Name
'i = 1
'Do While i < LTSheets
'    i = i + 1
For i = 2 To LTSheets
    Set pptSlide = pptApp.Presentations(LTTemp).Slides.Add(i, ppLayoutBlank)
    pptApp.Presentations(LTTemp).Slides(i).Select
    With ActiveSheet
        If .Name = "GPS_Data" Then
            Application.Sheets(i).Activate
            .Pictures.Select
            .Pictures.Copy
            pptApp.ActivePresentation.Slides(i).Select
            pptSlide.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture).Select
            pptApp.ActiveWindow.Selection.ShapeRange.Width = 720
            pptApp.ActiveWindow.Selection.ShapeRange.Top = 42
            pptApp.ActiveWindow.Selection.ShapeRange.Left = 0
        Else
            Application.Sheets(i).Activate
            Range("A1").Select
            Range("A1:AA39").Copy
            pptApp.Presentations(LTTemp).Slides(i).Select
            pptSlide.Shapes.PasteSpecial(DataType:=ppPasteBitmap).Select
            pptApp.ActiveWindow.Selection.ShapeRange.Width = 720
            pptApp.ActiveWindow.Selection.ShapeRange.Top = 42
            pptApp.ActiveWindow.Selection.ShapeRange.Left = 0
        End If
    End With
Next i
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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