将Excel图表发送到PowerPoint质量和大小
这是我将图表发送到特定位置的代码,如下所示:将Excel图表发送到PowerPoint质量和大小,excel,vba,powerpoint,Excel,Vba,Powerpoint,这是我将图表发送到特定位置的代码,如下所示: Sub This() Dim PPApp As PowerPoint.Application Dim PPPres As PowerPoint.Presentation Dim PPSlide As PowerPoint.Slide Set PPApp = New PowerPoint.Application Set pptPres = PPApp.Presentations.Open("C:\Template.pptx") Set PP
Sub This()
Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Set PPApp = New PowerPoint.Application
Set pptPres = PPApp.Presentations.Open("C:\Template.pptx")
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
' Copy the range as a picture
Sheets("Plots").ChartObjects("Chart Name").Copy
' Paste the range
With PPPres.Slides(10).Shapes.PasteSpecial
' Align pasted chart
.Align msoAlignCenters, True
.Align msoAlignMiddles, True
End With
End Sub
因此,这与假设的一样,它打开一张特定的PowerPoint幻灯片,并将图表发送到幻灯片10。我的问题是,有没有一种方法可以将绘图发送到特定的位置并使其具有一定的大小 Adam,试试下面的代码,与我在电脑上做的测试配合得很好 图表位置和大小根据我在最后4行中输入的值进行了修改
Sub This()
Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Set PPApp = New PowerPoint.Application
Set pptPres = PPApp.Presentations.Open("C:\Template.pptx")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
' Copy the range as a picture
Worksheets("Plots").ChartObjects("Chart Name").Copy
Set PPSlide = PPApp.ActivePresentation.Slides(10)
' Paste the Chart
With PPSlide.Shapes.PasteSpecial
.Top = 100
.Left = 120
.Height = 200
.Width = 400
End With
End Sub
PasteSpecial具有
.Top.Left
等特性。因此,这些可以用来对齐和调整照片的大小。我还注意到,如果使用Paste
而不是PasteSpecial
,则照片质量更差 我收到一个错误,提示ShaperAge(未知成员):请求无效。要选择形状,其视图必须处于活动状态。我在PPApp.Shapes.PasteSpecial.select上遇到错误line@AdamWarner尝试修改后的代码。B.T.W之前的代码对我有用,我测试了几次,没有得到你的错误(奇怪),冒着学究的风险:PasteSpecial是一个返回ShapeRange对象的方法。它是具有.Top、.Left等属性的ShapeRange对象。是的。好啊完全学识渊博。@SteveRindsberg知道正确的行话总是很好。@AdamWarner所以你用了我90%的代码,没有给我+1?@ShaiRado你的代码之前给了我一个错误,所以我没有给你+1。我就这么做了。
Sub This()
Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Set PPApp = New PowerPoint.Application
Set pptPres = PPApp.Presentations.Open("C:\Template.pptx")
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
' Copy the range as a picture
Sheets("Plots").ChartObjects("Chart Name").Copy
' Paste the range
With PPPres.Slides(10).Shapes.PasteSpecial
' Align pasted chart
.Top = 100.84976
.Left = 85.98417
.Height = 120.7964
.Width = 546.5262
End With
End Sub