Excel VBA paste to PowerPoint Slide using slide name

hawk771960

New Member
Joined
Jun 23, 2015
Messages
10
Building a PowerPoint presentation from Excel. PowerPoint and the file open properly and it fails when selecting the PowerPoint Slide. Feel free to comment on other coding adjustments you feel need cleaning up.

Sub OpenPPTPresent() 'Opens a PowerPoint Document from Excel


Dim PPT As Object
Dim Slide As Object
Dim Shape As Object
Dim PPTFile As String
Dim mcdb As Workbook
Dim FilePathFileName As String

Set mcdb = ActiveWorkbook
Set PPT = CreateObject("PowerPoint.Application")

FilePathFileName = "R:\Test\KGN MCDB Blank.pptx"

mcdb.Sheets("Report Summary").Range("B2:F2").Copy

PPT.Visible = True
PPT.Presentations.Open FilePathFileName

Slide = "EHS" ' Here is where I am having trouble ********

Slide.Slides.PasteSpecial DataType:=2
'Slide.Shapes.PasteSpecial DataType:=2 '2 = ppPasteEnhancedMetafile
'Shape.Left = 66
'Shape.Top = 152


End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try...

Code:
Sub OpenPPTPresent() 'Opens a PowerPoint Document from Excel


    Dim PPT As Object
    Dim PPres As Object
    Dim Slide As Object
    Dim Shape As Object
    Dim PPTFile As String
    Dim mcdb As Workbook
    Dim FilePathFileName As String
    
    Set mcdb = ActiveWorkbook
    Set PPT = CreateObject("PowerPoint.Application")
    
    FilePathFileName = "R:\Test\KGN MCDB Blank.pptx"
    
    mcdb.Sheets("Report Summary").Range("B2:F2").Copy
    
    PPT.Visible = True
    Set PPres = PPT.Presentations.Open(FilePathFileName)
    
    Set Slide = PPres.slides("EHS") ' Here is where I am having trouble ********
    
    Set Shape = Slide.Shapes.PasteSpecial(DataType:=2)(1) '2 = ppPasteEnhancedMetafile
    
    With Shape
        .Left = 66
        .Top = 152
    End With


End Sub

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,301
Members
452,633
Latest member
DougMo

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