-
Jun 8th, 2021, 12:50 PM
#1
Thread Starter
New Member
How to change plot area size of a shape pasted from an Excel file to a powerpoint?
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.
Code:
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
-
Jun 9th, 2021, 04:57 AM
#2
Re: How to change plot area size of a shape pasted from an Excel file to a powerpoint
i do not have powerpoint, so can not give an authoritative answer, but if i was trying to do it, i would look to create a temporary chart, as desired, in excel then just copy that to powerpoint
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|