I have this VBA that works beautifully as far as copying my two charts from Excel and placing them in a single Powerpoint slide. Except for one small thing that is driving me bonkers. The first chart resizes and is placed exactly where I want it on the slide. However, I cannot figure out how to resize the second chart and place it in right next to the first chart. Can someone please help me?
Sub Open_PowerPoint_Presentation()
'Opens a PowerPoint Document from Excel
Dim objPPT As Object
Dim activeSlide As PowerPoint.Slide
Dim cht As Excel.ChartObject
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
'path for the ppt
objPPT.Presentations.Open "path\powerpoint.pptx"
For Each cht In ActiveSheet.ChartObjects
objPPT.ActiveWindow.View.GotoSlide objPPT.ActivePresentation.Slides.Count
Set activeSlide = objPPT.ActivePresentation.Slides(objPPT.ActivePresentation.Slides.Count)
'Copy the chart and paste it into the PowerPoint as a picture
cht.Select
ActiveChart.ChartArea.Copy
activeSlide.Shapes.PasteSpecial(DataType:=ppPastePNG).Select
'resizing and placement of first chart
objPPT.ActiveWindow.Selection.ShapeRange.Left = 30
objPPT.ActiveWindow.Selection.ShapeRange.Top = 55
activeSlide.Shapes(1).Height = 400
activeSlide.Shapes(1).Width = 350
'resizing and placement of second chart
***this is the part that is not working***
' objPPT.ActiveWindow.Selection.ShapeRange.Left = 80
' objPPT.ActiveWindow.Selection.ShapeRange.Top = 55
' activeSlide.Shapes(2).Width = 400
' activeSlide.Shapes(2).Left = 350
Next
'more code goes here that works great
End Sub
Sub Open_PowerPoint_Presentation()
'Opens a PowerPoint Document from Excel
Dim objPPT As Object
Dim activeSlide As PowerPoint.Slide
Dim cht As Excel.ChartObject
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
'path for the ppt
objPPT.Presentations.Open "path\powerpoint.pptx"
For Each cht In ActiveSheet.ChartObjects
objPPT.ActiveWindow.View.GotoSlide objPPT.ActivePresentation.Slides.Count
Set activeSlide = objPPT.ActivePresentation.Slides(objPPT.ActivePresentation.Slides.Count)
'Copy the chart and paste it into the PowerPoint as a picture
cht.Select
ActiveChart.ChartArea.Copy
activeSlide.Shapes.PasteSpecial(DataType:=ppPastePNG).Select
'resizing and placement of first chart
objPPT.ActiveWindow.Selection.ShapeRange.Left = 30
objPPT.ActiveWindow.Selection.ShapeRange.Top = 55
activeSlide.Shapes(1).Height = 400
activeSlide.Shapes(1).Width = 350
'resizing and placement of second chart
***this is the part that is not working***
' objPPT.ActiveWindow.Selection.ShapeRange.Left = 80
' objPPT.ActiveWindow.Selection.ShapeRange.Top = 55
' activeSlide.Shapes(2).Width = 400
' activeSlide.Shapes(2).Left = 350
Next
'more code goes here that works great
End Sub
Last edited: