Hi all,
I have an Excel workbook with vba code to produce a PowerPoint presentation by copying, pasting, resizing and centering various Excel named ranges as OLE objects and it works perfectly when I run the code with my laptop connected to a docking station using separate display screens. If I try to run the code on my laptop alone it generates all the slides, copies and pastes all the ranges just fine, however, it does not resize the pasted object and does not center it on the slide. Here is an excerpt of the code I am using, the rest of it just repeats for other slides. Can someone tell me what I am missing please? I hope I'm posting this in the right place, any assistance would be gratefully received.
I have an Excel workbook with vba code to produce a PowerPoint presentation by copying, pasting, resizing and centering various Excel named ranges as OLE objects and it works perfectly when I run the code with my laptop connected to a docking station using separate display screens. If I try to run the code on my laptop alone it generates all the slides, copies and pastes all the ranges just fine, however, it does not resize the pasted object and does not center it on the slide. Here is an excerpt of the code I am using, the rest of it just repeats for other slides. Can someone tell me what I am missing please? I hope I'm posting this in the right place, any assistance would be gratefully received.
VBA Code:
Sub pPoint()
'Invoke PowerPoint
Dim pptapp As PowerPoint.Application
Dim pptppt As PowerPoint.Presentation
Dim pptslide As PowerPoint.Slide
Dim ws As Worksheet
Dim sld As Long
'Open PowerPoint
Set pptapp = New PowerPoint.Application
pptapp.Visible = msoTrue
pptapp.Activate
'Set Slide Master properties
Set pptppt = pptapp.Presentations.Add
pptppt.SlideMaster.Background.Fill.ForeColor.RGB = RGB(198, 224, 180)
sld = 1
'Set Title Slide
Set pptslide = pptppt.Slides.Add(sld, ppLayoutTitle)
Set ws = Sheet3
pptslide.Shapes(1).TextFrame.TextRange = "Weekly Review"
pptslide.Shapes(2).TextFrame.TextRange.Text = "Week " & Sheet3.Range("B2").Value
sld = sld + 1
'Add title slide
Set ws = Sheet1
Set pptslide = pptppt.Slides.Add(sld, ppLayoutTitleOnly)
pptslide.Select
pptslide.Shapes(1).TextFrame.TextRange = "Some Title"
pptslide.Shapes(1).TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
pptslide.Shapes(1).Select
pptapp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, msoTrue
pptapp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, msoTrue
sld = sld + 1
'Add kpi
Set pptslide = pptppt.Slides.Add(sld, ppLayoutBlank)
pptslide.Select
ws.Range("somekpi").Copy
pptslide.Shapes.PasteSpecial ppPasteOLEObject
pptslide.Shapes(1).Width = pptppt.PageSetup.SlideWidth
pptslide.Shapes(1).Select
pptapp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, msoTrue
pptapp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, msoTrue
sld = sld + 1