excel - 从excel(Excel VBA)插入后在PowerPoint中调整图表大小

标签 excel vba powerpoint

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

这是我的代码:

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

最佳答案

尝试这个:

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

所以你的代码的其余部分:
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

关于excel - 从excel(Excel VBA)插入后在PowerPoint中调整图表大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12983768/

相关文章:

excel - 打开时自动运行宏的好方法是什么

excel - 为什么 outlook.timezones.converttime 会导致 DST 更改错误?

甲骨文12c : Functions in the WITH Clause do not work with ADODB

excel - 使用 Excel VBA 打印 Word 文档而不打开它

VBA Excel在时间格式m/d/yyyy hh :mm:ss时发现时间差异

excel - 将大规模的值分配到数据库中。公式(libreOffice calc)

excel - 如何将变量设置为单元格地址?

vba - 对象 'Activate' 的偶尔 VBA 方法 'ChartData' 失败

macos - Powerpoint 的 AppleScript 命令的官方文档在哪里?

javascript - office.js 插入表格到 powerpoint