Excel to PowerPoint - Was working, not generating error....

BuJay

Board Regular
Joined
Jun 24, 2020
Messages
75
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
I am at a loss....this was working Friday....and now, when I went back to working on it this AM, it is no longer working....

1686577708086.png



VBA Code:
Sub CreateNewPres()

' Creating New PowerPoint and
' copying Table and Chart into the New
' PowerPoint Presentation

'Step 1) Add PowerPoint Reference Library - this is Early Binding

    Dim ppApp As PowerPoint.Application
    Set ppApp = New PowerPoint.Application
   
'Step 2) Add PowerPoint Object - this is Late Binding
   
    'Late Binding allows for version independence

'    Dim ppApp As Object
'    Set ppApp = CreateObject("PowerPoint.Application")
   
    ppApp.Visible = True
    ppApp.Activate
   
' Step 3) Create New Presentation within the Application

    Dim ppPres As PowerPoint.Presentation
    Set ppPres = ppApp.Presentations.Add
   
' Step 4) Create a Slide to the New Presentation

    Dim ppSlide As PowerPoint.Slide
   
    'Note that the Add() methos will probably not appear with intellisence
    'so may need to chage AddSlide() method to Add()
    Set ppSlide = ppPres.Slides.Add(1, ppLayoutTitle)
   
' Step 5) Adding Text to Textboxes

    ppSlide.Shapes(1).TextFrame.TextRange = "Here is the Title of the Presentation"
    ppSlide.Shapes(2).TextFrame.TextRange = "Here is the subtitle on title page"
   
' Step 6) Copying an Excel Range into PowerPoint

    ' Insert new slide
    Set ppSlide = ppPres.Slides.Add(2, ppLayoutBlank)
    ppSlide.Select
   
    'Copy data from Excel
    ThisWorkbook.Sheets("tables").Activate
    Range("D10").CurrentRegion.Copy

    'Paste Linked OLEObject
    ppSlide.Shapes.PasteSpecial DataType:=ppPasteOLEObject, Link:=True

' Step 7) Editing the Size and Position of Shapes
   
    ppSlide.Shapes(1).Select

    'Change shape width
    ppSlide.Shapes(1).Width = (ppPres.PageSetup.SlideWidth) * 0.8

    'Change shape position from left edge
    'ppSlide.Shapes(1).Left = 50

    'Align shape horizontally using left
    ppSlide.Shapes(1).Left = _
        (ppPres.PageSetup.SlideWidth / 2) - (ppSlide.Shapes(1).Width) / 2
   
    'Align shape vertically using Align
    'ppApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, msoTrue
   
    'Align shape vertically using Top
    ppSlide.Shapes(1).Top = _
        (ppPres.PageSetup.SlideHeight / 2) - (ppSlide.Shapes(1).Height) / 2
    
' Step 8) Adding and Formatting a Custom Textbox

    Dim ppTextBox As PowerPoint.Shape

    Set ppTextBox = ppSlide.Shapes.AddTextbox( _
        msoTextOrientationHorizontal, 0, 20, ppPres.PageSetup.SlideWidth, 60)

    'After we have set the ppTextBox above, we can use the .with block

    With ppTextBox.TextFrame
        .TextRange.Text = "     This is some text that I have added."
        .TextRange.ParagraphFormat.Alignment = ppAlignLeft
        .TextRange.Font.Size = 26
        .TextRange.Font.Name = "Calibri"
        .VerticalAnchor = msoAnchorMiddle
    End With

' Step 9) Copying and Pasting Charts from Excel into PowerPoint

    ' Insert new slide
    Set ppSlide = ppPres.Slides.Add(3, ppLayoutBlank)
    ppSlide.Select

    'Copy data from Excel
    ThisWorkbook.Sheets("charts").Activate
    ThisWorkbook.Sheets("charts").ChartObjects("Chart 3").Copy
   
'    'Paste Linked OLEObject

' THIS LINE BELOW IS GENERATING THE ERROR
    ppSlide.Shapes.PasteSpecial ppPasteOLEObject, msoCTrue
   
' INTERESTINGLY, IF I PASTE A "ppPasteEnhancedMetafile", THE CODE WORKS
' SO IT HAS SOMETHING TO DO WITH THE OLEOBJECT
 
'This also causes error  
'    'Paste Linked OLEObject
'    ppSlide.Shapes.PasteSpecial DataType:=ppPasteOLEObject, Link:=True
   
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Strange....I rebooted my laptop and now it is working.....

Don't understand why it stopped working....but it seems to be working now.
 
Upvote 0

Forum statistics

Threads
1,224,811
Messages
6,181,080
Members
453,021
Latest member
Justyna P

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