Hi,
I'm brand new to VBA and have been stumbling my way through creating a macro that will allow an excel range to be copied and pasted to powerpoint. I need to ensure that the pasted version is editable so I've pasted as HTML.
So far I've got as far as copying the range, pasting as HTML into a powerpoint and resizing/positioning the table but pasting the range shrinks the size of the font down (also changes some of the format like row height).
The macro currently works but also brings up a run time error 13 type mismatch which I also don't know what the issue is (debug highlights on row: Set OTable = PowerPointApp.ActiveWindow.Selection.ShapeRange
Here's my code so far:
Sub CreatePPT()
'Copy and Paste Excel to PPT
Dim PPT As Object
Dim PPTPresentation As PowerPoint.Presentation
Dim PPTSlide As PowerPoint.Slide
Dim Range As Range
Dim CheckPointReportTable As Object
Dim PowerPointApp As Object
Dim myPresentation As Object
Dim mySlide As Object
Dim myShape As Object
Dim ppObject As Object
Dim Slides As Slides
Dim Slide As Slide
Dim pShape As PowerPoint.Shape
Dim OTable As PowerPoint.Table
'Create PowerPoint
'Create an Instance of PowerPoint
On Error Resume Next
'Is PowerPoint already opened?
Set PowerPointApp = GetObject(class:="PowerPoint.Application")
'Clear the error between errors
Err.Clear
'If PowerPoint is not already open then open PowerPoint
If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(class:="PowerPoint.Application")
'Handle if the PowerPoint Application is not found
If Err.Number = 429 Then
MsgBox "PowerPoint could not be found, aborting."
Exit Sub
End If
On Error GoTo 0
'Optimize Code
Application.ScreenUpdating = False
'Create a New Presentation
Set myPresentation = PowerPointApp.Presentations.Add
'Add a slide to the Presentation
Set mySlide = myPresentation.Slides.Add(1, 12) '12 = blank
'Copy Excel Range
Set Range = ThisWorkbook.ActiveSheet.Range("A1:AN87")
Range.Copy
mySlide.Shapes.PasteSpecial DataType:=ppPasteHTML
With PowerPointApp.ActiveWindow.Selection.ShapeRange
.Left = 0 * 28.34646
.Top = 0 * 28.34646
.Width = 33.87 * 28.34646
.Height = 19.05 * 28.34646
End With
Set OTable = PowerPointApp.ActiveWindow.Selection.ShapeRange
End Sub