PDA

View Full Version : How to change plot area size of a shape pasted from an Excel file to a powerpoint?



Adam Brave
06-08-2021, 10:47 AM
Hi!
I'm using the code below to copy paste some charts from an Excel file to a PowerPoint file. The macro is running from the Excel file. It works fine. I would like now to be able to adjust a little bit the plot area of the chart after it has been pasted on the powerpoint and not the whole size of the shape. In the code below I'm already adjusting the shape but all my attempts to adjust only the plot area failed.



Sub CopyChartFromExcelToPpt()
'Turn screen updating off to speed up your macro code. You won't be able to see what the macro is doing, but it will run faster. Remember to set the ScreenUpdating property back to True when your macro ends.
Application.ScreenUpdating = False


Dim PPT_object As PowerPoint.Application
Dim OpenPptDialogBox As Object
Dim oCht As Chart
Dim MyShape As Object


Set PPT_object = CreateObject("PowerPoint.Application")
Set OpenPptDialogBox = PPT_object.FileDialog(msoFileDialogOpen)


'Open the target PPT using dialog box:
If OpenPptDialogBox.Show = -1 Then
PPT_object.Presentations.Open (OpenPptDialogBox.SelectedItems(1))
End If


'Copy the chart from excel macro file
ActiveSheet.ChartObjects("Chart 3").Copy
'Paste the chart in slide 4 of PPT
Set MyShape = PPT_object.ActiveWindow.Presentation.Slides(4).Shapes.Paste


'Change the position of shape, its height and width
With MyShape
.Left = 17.25
.Top = 68.2307
.Height = 198.5074
.Width = 662.414897
End With

'Copy the chart from excel macro file
ActiveSheet.ChartObjects("Chart 6").Copy
'Paste the chart in slide 4 of PPT
Set MyShape = PPT_object.ActiveWindow.Presentation.Slides(4).Shapes.Paste

'Change the position of shape and its height and width
With MyShape
.Left = 17.25
.Top = 273.2619
.Height = 198.5074
.Width = 662.414897
End With

'Save and close the file
PPT_object.ActivePresentation.Save
Application.ScreenUpdating = True
PPT_object.Windows(1).Close
End Sub



Any help here, please?

Thanks in advance

Adam Brave
06-09-2021, 04:28 AM
Update:
I tried to use the code below to change the plot area but it is throwing the error "Object doesn't support this action" when it reaches the .Chart.PlotArea.Height = 90 line.


Dim PPT_object As PowerPoint.ApplicationWith PPT_object.ActiveWindow.Presentation.Slides(4).Shapes.Range
If .HasChart Then
.Chart.PlotArea.Height = 90
End If
End With

Can someone help me to understand why this line is giving this error?

Thanks