Share via

How to change font size when pasting excel table to powerpoint

Anonymous
2021-02-08T11:01:46+00:00

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

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2021-02-08T12:28:27+00:00

    Hi Jomar,

    Thanks for the response.

    It makes sense - but is there anything I can do about this? Either to amend the font size or to change the formatting as part of the script?

    I can manually change the font size within the PPT manually, but it would be ideal if i could change it as part of this.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2021-02-08T11:35:19+00:00

    Good Day, Hi, This is Jomar,

    Thank you for reaching out to us. I am an Independent Advisor and Microsoft user like you.

    I have a link for you:

    https://answers.microsoft.com/en-us/msoffice/fo...

    If you have any questions, please let me know and I'd be glad to assist you further.

    Thank you and Best Regards!

    Was this answer helpful?

    0 comments No comments