BuJay
Board Regular
- Joined
- Jun 24, 2020
- Messages
- 75
- Office Version
- 365
- 2019
- 2016
- 2013
- Platform
- 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....
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