发送 Excel 图表到 PowerPoint 质量和大小
Sending Excel Chart To PowerPoint Quality And Size
这是我将图表发送到特定位置的代码如下:
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,试试下面的代码,它与我在我的 PC 上完成的测试配合得很好。
图表位置和大小已根据我在添加的最后 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
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
PasteSpecial具有.Top .Left
等特点。所以这些可以用来对齐和调整照片的大小。我还注意到,如果您使用 Paste
而不是 PasteSpecial
,那么照片质量会更差。
这是我将图表发送到特定位置的代码如下:
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,试试下面的代码,它与我在我的 PC 上完成的测试配合得很好。
图表位置和大小已根据我在添加的最后 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
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
PasteSpecial具有.Top .Left
等特点。所以这些可以用来对齐和调整照片的大小。我还注意到,如果您使用 Paste
而不是 PasteSpecial
,那么照片质量会更差。