从excel(Excel VBA)插入后调整powerpoint中的图表大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12983768/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 18:09:15  来源:igfitidea点击:

Resizing chart in powerpoint after inserting it from excel (Excel VBA)

excelvbapowerpoint

提问by Andrew

I have some code that takes a chart in exceland pastes it into a powerpointslide. However, once it is pasted into powerpointI'm not sure how to resize the chart. I've looked into finding which number "shape" it is and I can do this manually but I don't know how to automate this. Any help would be appreciated, thanks!

我有一些代码可以在excel中获取图表并将其粘贴到powerpoint幻灯片中。但是,一旦将其粘贴到powerpoint 中,我不确定如何调整图表的大小。我一直在寻找它是哪个数字“形状”,我​​可以手动执行此操作,但我不知道如何自动执行此操作。任何帮助将不胜感激,谢谢!

Here is my code:

这是我的代码:

Sub AddChartToPPT(PPT As PowerPoint.Application, Slide As Integer, Chart As String, FromTop As Double, FromLeft As Double, Length As Double, Width As Double)
Dim activeslide As PowerPoint.Slide
PPT.ActiveWindow.View.GotoSlide Slide
Set activeslide = PPT.ActivePresentation.Slides(Slide)
ActiveSheet.ChartObjects(Chart).Activate
ActiveChart.ChartArea.Copy
activeslide.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture).Select
PPT.ActiveWindow.Selection.ShapeRange.Left = FromLeft
PPT.ActiveWindow.Selection.ShapeRange.Top = FromTop
'Need to add scaling code
End Sub

回答by nutsch

Try this:

尝试这个:

dim shp as Object
set shp=activeslide.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture)
shp.Left = FromLeft
shp.Top = FromTop

so with the rest of your code:

所以对于你的其余代码:

Sub AddChartToPPT(PPT As PowerPoint.Application, Slide As Integer, Chart As String, FromTop As Double, FromLeft As Double, Length As Double, Width As Double)
Dim activeslide As PowerPoint.Slide, shp as Object
PPT.ActiveWindow.View.GotoSlide Slide
Set activeslide = PPT.ActivePresentation.Slides(Slide)
ActiveSheet.ChartObjects(Chart).Activate
ActiveChart.ChartArea.Copy
set shp=activeslide.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture)
shp.Left = FromLeft
shp.Top = FromTop
'Need to add scaling code     
End Sub

回答by Jon Peltier

In my experience, it's easier to resize the chart object in Excel prior to pasting it into PowerPoint. First, Excel's object model is clearer. Second, resizing a metafile may result in distortion, while resizing the chart and pasting as a metafile that needs no resizing does not.

根据我的经验,在将图表对象粘贴到 PowerPoint 之前,在 Excel 中调整图表对象的大小会更容易。首先,Excel的对象模型更加清晰。其次,调整图元文件大小可能会导致失真,而调整图表大小并粘贴为不需要调整大小的图元文件则不会。